зеркало из https://github.com/github/codeql.git
Merge pull request #4346 from RasmusWL/python-add-implicit-init-test
Python: add test for implicit __init__.py files
This commit is contained in:
Коммит
2e4a61428d
|
@ -0,0 +1,6 @@
|
|||
debug_missingAnnotationForCallable
|
||||
debug_nonUniqueAnnotationForCallable
|
||||
debug_missingAnnotationForCall
|
||||
expectedCallEdgeNotFound
|
||||
| example.py:19:1:19:7 | afunc() | foo/bar/a.py:2:1:2:12 | Function afunc |
|
||||
unexpectedCallEdgeFound
|
|
@ -0,0 +1 @@
|
|||
../CallGraph/PointsTo.ql
|
|
@ -0,0 +1,6 @@
|
|||
debug_missingAnnotationForCallable
|
||||
debug_nonUniqueAnnotationForCallable
|
||||
debug_missingAnnotationForCall
|
||||
pointsTo_found_typeTracker_notFound
|
||||
| example.py:22:1:22:16 | explicit_afunc() | foo_explicit/bar/a.py:2:1:2:21 | Function explicit_afunc |
|
||||
pointsTo_notFound_typeTracker_found
|
|
@ -0,0 +1 @@
|
|||
../CallGraph/Relative.ql
|
|
@ -0,0 +1,7 @@
|
|||
debug_missingAnnotationForCallable
|
||||
debug_nonUniqueAnnotationForCallable
|
||||
debug_missingAnnotationForCall
|
||||
expectedCallEdgeNotFound
|
||||
| example.py:19:1:19:7 | afunc() | foo/bar/a.py:2:1:2:12 | Function afunc |
|
||||
| example.py:22:1:22:16 | explicit_afunc() | foo_explicit/bar/a.py:2:1:2:21 | Function explicit_afunc |
|
||||
unexpectedCallEdgeFound
|
|
@ -0,0 +1 @@
|
|||
../CallGraph/TypeTracker.ql
|
|
@ -0,0 +1,22 @@
|
|||
"""
|
||||
Test that we can resolve callables correctly without using explicit __init__.py files
|
||||
|
||||
This is not included in the standard `CallGraph/code` folder, since we're testing our
|
||||
understanding import work properly, so it's better to have a clean test setup that is
|
||||
obviously correct (the other one isn't in regards to imports).
|
||||
|
||||
Technically this is part of PEP 420 -- Implicit Namespace Packages, but does use the
|
||||
*real* namespace package feature of allowing source code for a single package to reside
|
||||
in multiple places.
|
||||
|
||||
Since PEP 420 was accepted in Python 3, this test is Python 3 only.
|
||||
"""
|
||||
|
||||
from foo.bar.a import afunc
|
||||
from foo_explicit.bar.a import explicit_afunc
|
||||
|
||||
# calls:afunc
|
||||
afunc()
|
||||
|
||||
# calls:explicit_afunc
|
||||
explicit_afunc()
|
|
@ -0,0 +1,4 @@
|
|||
# name:afunc
|
||||
def afunc():
|
||||
print("afunc called")
|
||||
return 1
|
|
@ -0,0 +1,4 @@
|
|||
# name:explicit_afunc
|
||||
def explicit_afunc():
|
||||
print("explicit_afunc called")
|
||||
return 1
|
|
@ -0,0 +1 @@
|
|||
semmle-extractor-options: --max-import-depth=1 --lang=3
|
|
@ -1 +0,0 @@
|
|||
semmle-extractor-options:
|
|
@ -1 +1,3 @@
|
|||
# This import will only import code/__init__.py -- BUT we still analyse the other python
|
||||
# files inside code/ which is what we want.
|
||||
from code import *
|
||||
|
|
Загрузка…
Ссылка в новой задаче