ASTTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A test_iter_tree_return_all_objects() 0 5 1
A test_find_symbol_in_tree_ok() 0 4 1
A module_for_tests() 0 3 1
A get_ast_tree() 0 2 1
A test_find_symbol_in_tree_ko() 0 4 1
A test_get_ast_tree_ok() 0 3 1
1
# -*- coding: utf-8 -*-
2
import os
3
import ast
4
import unittest
5
6
import symboldoc
7
8
9
PATH = os.getcwd()
10
if 'tests' not in PATH:
11
    PATH += '/tests/'
12
13
14
class ASTTest(unittest.TestCase):
15
    @property
16
    def module_for_tests(self):
17
        return os.path.join(PATH, 'moduletest.py')
18
19
    def get_ast_tree(self):
20
        return symboldoc.get_ast_tree(self.module_for_tests)
21
22
    def test_get_ast_tree_ok(self):
23
        tree = self.get_ast_tree()
24
        self.assertIsInstance(tree, ast.Module)
25
26
    def test_iter_tree_return_all_objects(self):
27
        tree = self.get_ast_tree()
28
        items = list(symboldoc.iter_tree(tree))
29
        # 6: Module, Method, Return, Class, Method, Return
30
        self.assertEqual(len(items), 6)
31
32
    def test_find_symbol_in_tree_ok(self):
33
        tree = self.get_ast_tree()
34
        node = symboldoc.find_symbol_in_tree(tree, 'my_function')
35
        self.assertIsInstance(node, ast.FunctionDef)
36
37
    def test_find_symbol_in_tree_ko(self):
38
        tree = self.get_ast_tree()
39
        node = symboldoc.find_symbol_in_tree(tree, 'not_my_function')
40
        self.assertIsNone(node)
41