Skip to content

Commit 8efb44c

Browse files
committed
removing duplicate calls
1 parent fbdc1ce commit 8efb44c

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

inspect4py/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import requests
66
import subprocess
77
from pathlib import Path
8+
import collections
89

910
from json2html import *
1011
from bigcode_astgen.ast_generator import ASTGenerator
@@ -763,4 +764,9 @@ def update_list_calls(info, index_remove):
763764
if i in index_remove:
764765
continue
765766
updated_calls.append(info["calls"][i])
766-
return updated_calls
767+
### These lines are for removing duplicate calls
768+
res = []
769+
for i in updated_calls :
770+
if i not in res:
771+
res.append(i)
772+
return res

test/test_inspect4py.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ def test_call_list_nested(self):
5959
assert (call_list_data == dictionary)
6060

6161
def test_call_list_super_nested(self):
62-
dictionary = {'functions': {
63-
'func_d': {'local': ['super_nested_call.func_d.func_e'], 'nested': {'func_e': {'local': ['print']}}},
64-
'main': {'local': ['super_nested_call.MyClass.func_a',
65-
'super_nested_call.func_d']}}, 'body': {'local': ['super_nested_call.main']}, 'classes': {'MyClass': {
66-
'func_a': {'local': ['print', 'super_nested_call.MyClass.func_a.func_b'], 'nested': {
67-
'func_b': {'local': ['print', 'super_nested_call.MyClass.func_a.func_b.func_c'],
68-
'nested': {'func_c': {'local': ['print']}}}}}}}}
62+
dictionary = {'functions': {'func_d': {'local': ['super_nested_call.func_d.func_e'],
63+
'nested': {'func_e': {'local': ['print']}}},
64+
'main': {'local': ['super_nested_call.MyClass.func_a', 'super_nested_call.func_d']}},
65+
'body': {'local': ['super_nested_call.main']},
66+
'classes': {'MyClass': {'func_a': {'local': ['print', 'super_nested_call.MyClass.func_a.func_b'],
67+
'nested': {'func_b': {'local': ['print', 'super_nested_call.MyClass.func_a.func_b.func_c'],
68+
'nested': {'func_c': {'local': ['print']}}}}}}}}
6969
input_path = "./test_files/test_inheritance/super_nested_call.py"
7070
output_dir = "./output_dir"
7171
control_flow = False
@@ -74,14 +74,13 @@ def test_call_list_super_nested(self):
7474
source_code = False
7575
cf_dir, json_dir = create_output_dirs(output_dir, control_flow)
7676
code_info = CodeInspection(input_path, cf_dir, json_dir, fig, control_flow, abstract_syntax_tree, source_code)
77-
7877
call_list_data = call_list_file(code_info)
7978
shutil.rmtree(output_dir)
8079
assert (call_list_data == dictionary)
8180

8281
def test_call_list_import(self):
8382
dictionary = {'functions': {'funct_D': {'local': ['print', 'test_functions.funct_A']}}, 'body': {
84-
'local': ['test_functions.funct_A', 'test_import.funct_D', 'test_import.funct_D']},
83+
'local': ['test_functions.funct_A', 'test_import.funct_D']},
8584
'classes': {'MyClass_D': {'__init__': {'local': ['print', 'test_functions.funct_C', 'test_import.funct_D']}},
8685
'MyClass_E': {'__init__': {'local': ['print']}}}}
8786
input_path = "./test_files/test_inheritance/test_import.py"
@@ -98,8 +97,7 @@ def test_call_list_import(self):
9897

9998
def test_call_list_external_module(self):
10099
dictionary = {'body': {
101-
'local': ['random.seed', 'print', 'random.random', 'random.random', 'random.random', 'random.seed', 'print',
102-
'random.random', 'random.random', 'random.random']}}
100+
'local': ['random.seed', 'print', 'random.random']}}
103101
input_path = "./test_files/test_random.py"
104102
output_dir = "./output_dir"
105103
control_flow = False
@@ -238,8 +236,6 @@ def test_call_list_dynamic_import_method_variable(self):
238236
code_info = CodeInspection(input_path, cf_dir, json_dir, fig, control_flow, abstract_syntax_tree, source_code)
239237
call_list_data = call_list_file(code_info)
240238
shutil.rmtree(output_dir)
241-
print(call_list_data)
242-
print(dictionary)
243239
assert (call_list_data == dictionary)
244240

245241
def test_call_list_dynamic_class_import(self):

0 commit comments

Comments
 (0)