Пример #1
0
def add_calls(graph: Node):
    for node in [n for n in graph if type(n) == FileNode]:
        filepath = node.location
        lines = fh.reader(filepath)

        for place, line in enumerate(lines):
            if fnc_call := get_fnc_calls(
                    line):  # if this line calls a function...
                if fnc_node := xfs(
                        graph, tgt_node=FncNode,
                        tgt_nm=fnc_call[0]):  # if called function in graph...
                    call_owner = get_fnc_from_line(
                        lines,
                        place)  # get the name of function calling fnc_node
                    caller_node = xfs(
                        graph, tgt_node=FncNode, tgt_nm=call_owner
                    )  # get the node of the function calling fnc_node
                    caller_node.add_call(fnc_node)
Пример #2
0
 def test_doesnt_catch_def(self):
     output = get_fnc_calls("def test():")
     self.assertEqual(output, ())
Пример #3
0
 def test_returns_falsy(self):
     output = get_fnc_calls("a = 'hi'")
     self.assertEqual(output, ())
Пример #4
0
 def test_aliased_fnc(self):
     output = get_fnc_calls("a.test()")
     self.assertEqual(output, ("test",))
Пример #5
0
 def test_multiple_fncs(self):
     output = get_fnc_calls("test(); test2()")
     self.assertEqual(output, ("test", "test2"))
Пример #6
0
 def test_fnc_with_params(self):
     output = get_fnc_calls("test(x)")
     self.assertEqual(output, ("test",))