python: add tests for module import

- `--max-import-depth=3` to give points-to a chance
- `not_root` dir to force namespace package logic
- add usage in `example.py` to get files extracted
This commit is contained in:
Rasmus Lerchedahl Petersen
2023-08-28 14:21:34 +02:00
committed by yoff
parent dbecb1bd0f
commit 362cf107a4
8 changed files with 29 additions and 5 deletions

View File

@@ -16,7 +16,13 @@ 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
from not_root.baz.foo import foo_func
from not_root.baz.bar.a import afunc as afunc2
afunc() # $ pt,tt="foo/bar/a.py:afunc"
explicit_afunc() # $ pt,tt="foo_explicit/bar/a.py:explicit_afunc"
foo_func() # $ pt,tt="not_root/baz/foo.py:foo_func"
afunc2() # $ pt,tt="not_root/baz/bar/a.py:afunc"

View File

@@ -1,3 +1,6 @@
def afunc():
print("afunc called")
return 1
print("afunc called")
return 1
from foo.foo import foo_func
foo_func() # $ pt,tt="foo/foo.py:foo_func"

View File

@@ -0,0 +1,2 @@
def foo_func():
print("foo_func called")

View File

@@ -1,3 +1,6 @@
def explicit_afunc():
print("explicit_afunc called")
return 1
print("explicit_afunc called")
return 1
from foo_explicit.foo_explicit import foo_explicit_func
foo_explicit_func() # $ pt,tt="foo_explicit/foo_explicit.py:foo_explicit_func"

View File

@@ -0,0 +1,2 @@
def foo_explicit_func():
print("foo_explicit_func called")

View File

@@ -0,0 +1,6 @@
def afunc():
print("afunc called")
return 1
from baz.foo import foo_func
foo_func() # $ MISSING: pt,tt="baz/foo.py:foo_func"

View File

@@ -0,0 +1,2 @@
def foo_func():
print("foo_func called")

View File

@@ -1 +1 @@
semmle-extractor-options: --max-import-depth=1 --lang=3
semmle-extractor-options: --max-import-depth=3 --lang=3