Пример #1
0
 def test_ancestors(self):
     definitions = analyze.find_definitions('tests/files/example.py')
     found_class = analyze.find_class('start', definitions)
     ancestors = found_class.calls[0].calls[0].ancestors()
     self.assertEqual(ancestors[0], funct('start'))
     self.assertEqual(ancestors[1], cls('Example', funct('somethingelse')))
     self.assertEqual(ancestors[2], cls("ThingTwo", funct("two")))
Пример #2
0
    def test_find_class_follows_function_class_calls(self):
        definitions = analyze.find_definitions('tests/files/example.py')
        found_funct = analyze.find_class('start', definitions)

        self.assertEqual(found_funct.name, 'start')
        self.assertEqual(len(found_funct.calls), 1)
        self.assertEqual(found_funct.calls[0],
                         cls('Example', funct('somethingelse')))
Пример #3
0
 def test_cycles_short_circit(self):
     definitions = analyze.find_definitions('tests/files/more_examples.py')
     found_class = analyze.find_class('zed', definitions)
     self.assertEqual(len(found_class.calls), 1)
     self.assertEqual(cls('ThingThree', funct('call_cycle')),
                      found_class.calls[0])
     self.assertTrue(found_class.calls[0].calls[0].cycle)
     self.assertEqual(cls("ContainsCycle", funct('zed')),
                      found_class.calls[0].calls[0])
Пример #4
0
    def test_create_graph_file(self):
        import lxml.etree
        import cssselect
        test_files_name = 'tests/files/tmp/tree_file.html'

        definitions = analyze.find_definitions_in_directory('tests/files')
        tree = analyze.find_class('start', definitions)
        analyze.save_tree(tree, test_files_name)

        doc = lxml.etree.fromstring(pathlib.Path(test_files_name).read_text())
        first_call_h2_element = doc.cssselect('div.class_def h2')
        self.assertEqual(first_call_h2_element[0].text.strip(), "start")
        second_call_h3_element = first_call_h2_element[0].getparent(
        ).cssselect("div.calls h3")
        self.assertEqual(second_call_h3_element[0].text.strip(),
                         'Example.somethingelse')
        third_call_h3_element = second_call_h3_element[0].getparent(
        ).cssselect("div.calls h3")
        self.assertEqual(third_call_h3_element[0].text.strip(), 'ThingTwo.two')

        os.remove(test_files_name)
        self.assertFalse(os.path.exists(test_files_name))
Пример #5
0
 def test_find_class(self):
     definitions = analyze.find_definitions('tests/files/example.py')
     self.assertEqual(cls('Example', funct('somethingelse')),
                      analyze.find_class('somethingelse', definitions))
Пример #6
0
 def test_calls_link_to_their_parent(self):
     definitions = analyze.find_definitions('tests/files/example.py')
     found_class = analyze.find_class('somethingelse', definitions)
     self.assertEqual(cls('Example', funct('somethingelse')),
                      found_class.calls[0].parent)
Пример #7
0
 def test_find_class_is_recursive(self):
     definitions = analyze.find_definitions('tests/files/example.py')
     found_class = analyze.find_class('somethingelse', definitions)
     self.assertEqual(len(found_class.calls), 1)
     self.assertEqual(cls('ThingTwo', funct('two')), found_class.calls[0])
Пример #8
0
 def test_find_class_returns_functions(self):
     definitions = analyze.find_definitions('tests/files/example.py')
     self.assertEqual(funct('start'),
                      analyze.find_class('start', definitions))
Пример #9
0
 def test_find_class_return_none_when_no_match(self):
     definitions = analyze.find_definitions('tests/files/example.py')
     self.assertEqual(None, analyze.find_class('notafunction', definitions))