Skip to content

Commit 2e4a614

Browse files
authored
Merge pull request #4346 from RasmusWL/python-add-implicit-init-test
Python: add test for implicit __init__.py files
2 parents 55d25d9 + 2acfd4c commit 2e4a614

File tree

14 files changed

+55
-1
lines changed

14 files changed

+55
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
debug_missingAnnotationForCallable
2+
debug_nonUniqueAnnotationForCallable
3+
debug_missingAnnotationForCall
4+
expectedCallEdgeNotFound
5+
| example.py:19:1:19:7 | afunc() | foo/bar/a.py:2:1:2:12 | Function afunc |
6+
unexpectedCallEdgeFound
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../CallGraph/PointsTo.ql
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
debug_missingAnnotationForCallable
2+
debug_nonUniqueAnnotationForCallable
3+
debug_missingAnnotationForCall
4+
pointsTo_found_typeTracker_notFound
5+
| example.py:22:1:22:16 | explicit_afunc() | foo_explicit/bar/a.py:2:1:2:21 | Function explicit_afunc |
6+
pointsTo_notFound_typeTracker_found
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../CallGraph/Relative.ql
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
debug_missingAnnotationForCallable
2+
debug_nonUniqueAnnotationForCallable
3+
debug_missingAnnotationForCall
4+
expectedCallEdgeNotFound
5+
| example.py:19:1:19:7 | afunc() | foo/bar/a.py:2:1:2:12 | Function afunc |
6+
| example.py:22:1:22:16 | explicit_afunc() | foo_explicit/bar/a.py:2:1:2:21 | Function explicit_afunc |
7+
unexpectedCallEdgeFound
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../CallGraph/TypeTracker.ql
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Test that we can resolve callables correctly without using explicit __init__.py files
3+
4+
This is not included in the standard `CallGraph/code` folder, since we're testing our
5+
understanding import work properly, so it's better to have a clean test setup that is
6+
obviously correct (the other one isn't in regards to imports).
7+
8+
Technically this is part of PEP 420 -- Implicit Namespace Packages, but does use the
9+
*real* namespace package feature of allowing source code for a single package to reside
10+
in multiple places.
11+
12+
Since PEP 420 was accepted in Python 3, this test is Python 3 only.
13+
"""
14+
15+
from foo.bar.a import afunc
16+
from foo_explicit.bar.a import explicit_afunc
17+
18+
# calls:afunc
19+
afunc()
20+
21+
# calls:explicit_afunc
22+
explicit_afunc()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# name:afunc
2+
def afunc():
3+
print("afunc called")
4+
return 1

python/ql/test/experimental/library-tests/CallGraph-implicit-init/foo_explicit/__init__.py

Whitespace-only changes.

python/ql/test/experimental/library-tests/CallGraph-implicit-init/foo_explicit/bar/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)