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")))
def test_find_definitions(self): definitions = analyze.find_definitions('tests/files/example.py') self.assertIn(funct('start'), definitions) self.assertIn(cls('ThingTwo', funct('two')), definitions) self.assertIn( cls('Example', funct('something'), funct('somethingelse')), definitions)
def test_find_definitions_in_directory(self): definitions = analyze.find_definitions_in_directory('tests/files') self.assertIn(funct('start'), definitions) self.assertIn( cls('Example', funct('something'), funct('somethingelse')), definitions) self.assertIn(cls('ThingThree', funct('baz'), funct('call_cycle')), definitions)
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])
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')))
def test_class_to_dict(self): self.assertEqual( cls('testclass', funct('foo', calls=['one']), funct('bar'), from_file='testfile.py').to_dict(), { 'name': 'testclass', 'type': 'class', 'from_file': 'testfile.py', 'functions': [{ 'name': 'foo', 'type': 'function', 'calls': ['one'], 'from_file': None }, { 'name': 'bar', 'type': 'function', 'calls': [], 'from_file': None }] })
def test_find_class(self): definitions = analyze.find_definitions('tests/files/example.py') self.assertEqual(cls('Example', funct('somethingelse')), analyze.find_class('somethingelse', definitions))
def test_get_funct_name(self): self.assertEqual( cls("Example", funct('testtest')).get_funct('testtest'), funct('testtest')) self.assertEqual( cls("Example", funct('testtest')).get_funct('nothere'), None)
def test_class_equality_with_functions(self): self.assertTrue( cls('ThingTwo', funct('one'), funct('two')) == cls( 'ThingTwo', funct('one'), funct('two')))
def test_class_not_equal(self): self.assertFalse(cls('ThingOne') == cls('ThingTwo'))
def test_class_equality(self): self.assertTrue(cls('ThingTwo') == cls('ThingTwo'))
def test_class_funcaiton_names(self): self.assertEqual( cls("Test", funct("one"), funct('two')).function_names(), ['one', 'two'])
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)
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])