Python: Add test cases

This commit is contained in:
Rasmus Lerchedahl Petersen
2024-06-27 16:33:23 +02:00
parent 27301edc28
commit 9cca1b294c
5 changed files with 27 additions and 6 deletions

View File

@@ -85,9 +85,10 @@ class Scope extends Scope_ {
this instanceof Module
or
exists(Module m | m = this.getEnclosingScope() and m.isPublic() |
/* If the module has an __all__, is this in it */
// The module is implicitly exported
not exists(getAModuleExport(m))
or
// The module is explicitly exported
getAModuleExport(m) = this.getName()
)
or

View File

@@ -8,4 +8,8 @@
| MyPackage/Foo.py:20:5:20:27 | Function c2only_m1 | MyPackage | Foo.C2 | c2only_m1 | (self,x) | false | Foo.py | | InstanceMethod |
| MyPackage/Foo.py:23:1:23:9 | Class C3 | MyPackage | Foo.C3 | | | false | Foo.py | | Class |
| MyPackage/Foo.py:24:5:24:26 | Function get_C2_instance | MyPackage | Foo.C3 | get_C2_instance | () | false | Foo.py | | InstanceMethod |
| TopLevel.py:3:1:3:38 | Function top_level_funciton | TopLevel | | top_level_funciton | (x,y,z:) | false | TopLevel.py | | Function |
| MyPackage/Foo.py:31:1:31:38 | Function top_level_function | MyPackage | Foo | top_level_function | (x,y,z:) | false | Foo.py | | Function |
| MyPackage/Foo.py:34:1:34:42 | Function func_with_fancy_args | MyPackage | Foo | func_with_fancy_args | () | false | Foo.py | | Function |
| MyPackage/ModuleWithAll.py:2:1:2:10 | Class Foo | MyPackage | ModuleWithAll.Foo | | | false | ModuleWithAll.py | | Class |
| MyPackage/ModuleWithAll.py:3:1:3:10 | Class Bar | MyPackage | ModuleWithAll.Bar | | | false | ModuleWithAll.py | | Class |
| TopLevel.py:3:1:3:38 | Function top_level_function | TopLevel | | top_level_function | (x,y,z:) | false | TopLevel.py | | Function |

View File

@@ -22,4 +22,14 @@ class C2(C1):
class C3:
def get_C2_instance():
return C2()
return C2()
class C3nested:
def m5(self, x):
return x
def top_level_function(x, /, y, *, z):
return [x, y, z]
def func_with_fancy_args(*args, **kwargs):
return args, kwargs

View File

@@ -0,0 +1,3 @@
__all__ = ['Foo']
class Foo: pass
class Bar: pass

View File

@@ -1,8 +1,11 @@
from MyPackage import Foo
from MyPackage import Foo, ModuleWithAll
def top_level_funciton(x, /, y, *, z):
def top_level_function(x, /, y, *, z):
return [x, y, z]
top_level_value = Foo.C1()
iC2 = Foo.C3.get_C2_instance()
iC2 = Foo.C3.get_C2_instance()
f = ModuleWithAll.Foo()
b = ModuleWithAll.Bar()