Skip to content

Commit 70ec2d0

Browse files
committed
Add unit-test for python-security#197
This checks imports of functions with name collisions are resolved correctly.
1 parent 40c1f24 commit 70ec2d0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .multiple_files.C import foo as foo_c
2+
from .multiple_files.D import foo as foo_d
3+
4+
c = foo_c('from_c')
5+
d = foo_d('from_d')

tests/cfg/import_test.py

+36
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,42 @@ def test_multiple_files_with_aliases(self):
406406
for node, expected_label in zip(self.cfg.nodes, EXPECTED):
407407
self.assertEqual(node.label, expected_label)
408408

409+
def test_from_multiple_files_with_aliases(self):
410+
"""Make sure that when two functions are imported that have the same name, they are aliased correctly."""
411+
file_path = os.path.normpath('examples/import_test_project/test_from_multiple_files_with_aliases.py')
412+
project_path = os.path.normpath('examples/import_test_project')
413+
414+
project_modules = get_modules_and_packages(project_path)
415+
local_modules = get_directory_modules(project_path)
416+
417+
self.cfg_create_from_file(file_path, project_modules, local_modules)
418+
419+
EXPECTED = ["Entry module",
420+
"Module Entry multiple_files.C",
421+
"Module Exit multiple_files.C",
422+
"Module Entry multiple_files.D",
423+
"Module Exit multiple_files.D",
424+
"temp_1_s = 'from_c'",
425+
"s = temp_1_s",
426+
"Function Entry foo",
427+
"ret_foo_c = s + 'see'",
428+
"Exit foo",
429+
"~call_1 = ret_foo_c",
430+
"c = ~call_1",
431+
"save_2_c = c",
432+
"temp_2_s = 'from_d'",
433+
"s = temp_2_s",
434+
"Function Entry foo",
435+
"ret_foo_d = s + 'dee'",
436+
"Exit foo",
437+
"c = save_2_c",
438+
"~call_2 = ret_foo_d",
439+
"d = ~call_2",
440+
"Exit module"]
441+
442+
for node, expected_label in zip(self.cfg.nodes, EXPECTED):
443+
self.assertEqual(node.label, expected_label)
444+
409445
def test_multiple_functions_with_aliases(self):
410446
file_path = os.path.normpath('examples/import_test_project/test_multiple_functions_with_aliases.py')
411447
project_path = os.path.normpath('examples/import_test_project')

0 commit comments

Comments
 (0)