Skip to content

Commit 9cca1b2

Browse files
committed
Python: Add test cases
1 parent 27301ed commit 9cca1b2

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

python/ql/lib/semmle/python/Scope.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ class Scope extends Scope_ {
8585
this instanceof Module
8686
or
8787
exists(Module m | m = this.getEnclosingScope() and m.isPublic() |
88-
/* If the module has an __all__, is this in it */
88+
// The module is implicitly exported
8989
not exists(getAModuleExport(m))
9090
or
91+
// The module is explicitly exported
9192
getAModuleExport(m) = this.getName()
9293
)
9394
or

python/ql/test/modelling/FrameworkModeEndpoints.expected

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
| MyPackage/Foo.py:20:5:20:27 | Function c2only_m1 | MyPackage | Foo.C2 | c2only_m1 | (self,x) | false | Foo.py | | InstanceMethod |
99
| MyPackage/Foo.py:23:1:23:9 | Class C3 | MyPackage | Foo.C3 | | | false | Foo.py | | Class |
1010
| MyPackage/Foo.py:24:5:24:26 | Function get_C2_instance | MyPackage | Foo.C3 | get_C2_instance | () | false | Foo.py | | InstanceMethod |
11-
| TopLevel.py:3:1:3:38 | Function top_level_funciton | TopLevel | | top_level_funciton | (x,y,z:) | false | TopLevel.py | | Function |
11+
| MyPackage/Foo.py:31:1:31:38 | Function top_level_function | MyPackage | Foo | top_level_function | (x,y,z:) | false | Foo.py | | Function |
12+
| MyPackage/Foo.py:34:1:34:42 | Function func_with_fancy_args | MyPackage | Foo | func_with_fancy_args | () | false | Foo.py | | Function |
13+
| MyPackage/ModuleWithAll.py:2:1:2:10 | Class Foo | MyPackage | ModuleWithAll.Foo | | | false | ModuleWithAll.py | | Class |
14+
| MyPackage/ModuleWithAll.py:3:1:3:10 | Class Bar | MyPackage | ModuleWithAll.Bar | | | false | ModuleWithAll.py | | Class |
15+
| TopLevel.py:3:1:3:38 | Function top_level_function | TopLevel | | top_level_function | (x,y,z:) | false | TopLevel.py | | Function |

python/ql/test/modelling/MyPackage/Foo.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ def c2only_m1(self, x):
2222

2323
class C3:
2424
def get_C2_instance():
25-
return C2()
25+
return C2()
26+
27+
class C3nested:
28+
def m5(self, x):
29+
return x
30+
31+
def top_level_function(x, /, y, *, z):
32+
return [x, y, z]
33+
34+
def func_with_fancy_args(*args, **kwargs):
35+
return args, kwargs
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__all__ = ['Foo']
2+
class Foo: pass
3+
class Bar: pass

python/ql/test/modelling/TopLevel.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from MyPackage import Foo
1+
from MyPackage import Foo, ModuleWithAll
22

3-
def top_level_funciton(x, /, y, *, z):
3+
def top_level_function(x, /, y, *, z):
44
return [x, y, z]
55

66
top_level_value = Foo.C1()
77

8-
iC2 = Foo.C3.get_C2_instance()
8+
iC2 = Foo.C3.get_C2_instance()
9+
10+
f = ModuleWithAll.Foo()
11+
b = ModuleWithAll.Bar()

0 commit comments

Comments
 (0)