Esempio n. 1
0
 def test_handle_returns_func_in_func(self):
     tree = ast.parse(
         'def some_function():\n\tdef inside_function():\n\t\tpass\n\treturn inside_function()'
     )
     add_parents(tree)
     tree = FunctionDefHandler().handle(tree)
     tracker = DefinitionTracker.get_instance()
     handled_node = handle_returns(tree.body[0].body[1].value.func, tracker)
     self.assertEqual(handled_node.id, '_0x641')
Esempio n. 2
0
 def test_handle_returns_variable(self):
     tree = ast.parse(
         'def some_function():\n\tsome_variable = 42\n\treturn some_variable'
     )
     add_parents(tree)
     tree = FunctionDefHandler().handle(tree)
     tracker = DefinitionTracker.get_instance()
     handled_node = handle_returns(tree.body[0].body[1].value, tracker)
     self.assertEqual(handled_node.id, '_0x559')
Esempio n. 3
0
 def test_handle_returns_class(self):
     tree = ast.parse(
         'class SomeClass:\n\tpass\ndef some_function():\n\treturn SomeClass()'
     )
     add_parents(tree)
     tree = ClassDefHandler().handle(tree)
     tree = FunctionDefHandler().handle(tree)
     tracker = DefinitionTracker.get_instance()
     handled_node = handle_returns(tree.body[1].body[0].value.func, tracker)
     self.assertEqual(handled_node.id, '_0x38a')
Esempio n. 4
0
 def test_handle_returns_none(self):
     tree = ast.parse('def some_function():\n\tsome_variable = 42')
     add_parents(tree)
     tracker = DefinitionTracker.get_instance()
     handled_node = handle_returns(tree.body[0].body[0].targets[0], tracker)
     self.assertEqual(handled_node, tree.body[0].body[0].targets[0])