mirror of
https://github.com/github/codeql.git
synced 2025-12-21 19:26:31 +01:00
Python: Copy tests to Python 3
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
| __init__.py | 1 | ControlFlowNode for ImportExpr | Module package.module | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 2 | ControlFlowNode for ImportMember | Function module | ControlFlowNode for FunctionExpr |
|
||||
| __init__.py | 2 | ControlFlowNode for module | Function module | ControlFlowNode for FunctionExpr |
|
||||
| __init__.py | 4 | ControlFlowNode for ImportExpr | Module package | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 4 | ControlFlowNode for ImportMember | Module package.module2 | Entry node for Module package.module2 |
|
||||
| __init__.py | 4 | ControlFlowNode for module3 | Module package.module2 | Entry node for Module package.module2 |
|
||||
| __init__.py | 5 | ControlFlowNode for IntegerLiteral | int 7 | ControlFlowNode for IntegerLiteral |
|
||||
| __init__.py | 5 | ControlFlowNode for module2 | int 7 | ControlFlowNode for IntegerLiteral |
|
||||
| __init__.py | 6 | ControlFlowNode for ImportExpr | Module package | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 6 | ControlFlowNode for ImportMember | int 7 | ControlFlowNode for IntegerLiteral |
|
||||
| __init__.py | 6 | ControlFlowNode for module4 | int 7 | ControlFlowNode for IntegerLiteral |
|
||||
| __init__.py | 7 | ControlFlowNode for ImportExpr | Module package | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 7 | ControlFlowNode for ImportMember | Module package.module2 | Entry node for Module package.module2 |
|
||||
| __init__.py | 7 | ControlFlowNode for module5 | Module package.module2 | Entry node for Module package.module2 |
|
||||
| __init__.py | 8 | ControlFlowNode for ImportExpr | Module package | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 8 | ControlFlowNode for ImportMember | Module package.moduleX | Entry node for Module package.moduleX |
|
||||
| __init__.py | 8 | ControlFlowNode for moduleX | Module package.moduleX | Entry node for Module package.moduleX |
|
||||
| module2.py | 1 | ControlFlowNode for IntegerLiteral | int 0 | ControlFlowNode for IntegerLiteral |
|
||||
| module2.py | 1 | ControlFlowNode for x | int 0 | ControlFlowNode for IntegerLiteral |
|
||||
| module.py | 2 | ControlFlowNode for FunctionExpr | Function module | ControlFlowNode for FunctionExpr |
|
||||
| module.py | 2 | ControlFlowNode for module | Function module | ControlFlowNode for FunctionExpr |
|
||||
| moduleX.py | 1 | ControlFlowNode for ClassExpr | class Y | ControlFlowNode for ClassExpr |
|
||||
| moduleX.py | 1 | ControlFlowNode for Y | class Y | ControlFlowNode for ClassExpr |
|
||||
| moduleX.py | 1 | ControlFlowNode for object | builtin-class object | ControlFlowNode for object |
|
||||
| test.py | 1 | ControlFlowNode for ImportExpr | Module package | ControlFlowNode for ImportExpr |
|
||||
| test.py | 2 | ControlFlowNode for ImportMember | Function module | ControlFlowNode for FunctionExpr |
|
||||
| test.py | 2 | ControlFlowNode for module | Function module | ControlFlowNode for FunctionExpr |
|
||||
| test.py | 4 | ControlFlowNode for ImportExpr | Module package | ControlFlowNode for ImportExpr |
|
||||
| test.py | 5 | ControlFlowNode for ImportMember | Module package.x | Entry node for Module package.x |
|
||||
| test.py | 5 | ControlFlowNode for x | Module package.x | Entry node for Module package.x |
|
||||
| test.py | 8 | ControlFlowNode for C | class C | ControlFlowNode for ClassExpr |
|
||||
| test.py | 8 | ControlFlowNode for ClassExpr | class C | ControlFlowNode for ClassExpr |
|
||||
| test.py | 8 | ControlFlowNode for object | builtin-class object | ControlFlowNode for object |
|
||||
| test.py | 10 | ControlFlowNode for ImportExpr | Module package | ControlFlowNode for ImportExpr |
|
||||
| test.py | 10 | ControlFlowNode for ImportMember | int 7 | ControlFlowNode for IntegerLiteral |
|
||||
| test.py | 10 | ControlFlowNode for module2 | int 7 | ControlFlowNode for IntegerLiteral |
|
||||
| test.py | 12 | ControlFlowNode for FunctionExpr | Function f | ControlFlowNode for FunctionExpr |
|
||||
| test.py | 12 | ControlFlowNode for f | Function f | ControlFlowNode for FunctionExpr |
|
||||
| test.py | 13 | ControlFlowNode for ImportExpr | Module package | ControlFlowNode for ImportExpr |
|
||||
| test.py | 13 | ControlFlowNode for ImportMember | Module package.x | Entry node for Module package.x |
|
||||
| test.py | 13 | ControlFlowNode for x | Module package.x | Entry node for Module package.x |
|
||||
| test.py | 15 | ControlFlowNode for ImportExpr | Module package | ControlFlowNode for ImportExpr |
|
||||
| test.py | 15 | ControlFlowNode for ImportMember | Module package.moduleX | Entry node for Module package.moduleX |
|
||||
| test.py | 15 | ControlFlowNode for moduleX | Module package.moduleX | Entry node for Module package.moduleX |
|
||||
| test.py | 16 | ControlFlowNode for Attribute | class Y | ControlFlowNode for ClassExpr |
|
||||
| test.py | 16 | ControlFlowNode for moduleX | Module package.moduleX | Entry node for Module package.moduleX |
|
||||
| test.py | 19 | ControlFlowNode for ImportExpr | Module tty | ControlFlowNode for ImportExpr |
|
||||
| test.py | 19 | ControlFlowNode for tty | Module tty | ControlFlowNode for ImportExpr |
|
||||
| test.py | 22 | ControlFlowNode for Attribute | Builtin-function exc_info | ControlFlowNode for from sys import * |
|
||||
| test.py | 22 | ControlFlowNode for x | Module package.x | Entry node for Module package.x |
|
||||
| test.py | 24 | ControlFlowNode for IntegerLiteral | int 0 | ControlFlowNode for IntegerLiteral |
|
||||
| test.py | 24 | ControlFlowNode for argv | int 0 | ControlFlowNode for IntegerLiteral |
|
||||
| test.py | 27 | ControlFlowNode for ImportExpr | Module sys | ControlFlowNode for ImportExpr |
|
||||
| test.py | 31 | ControlFlowNode for argv | list object | ControlFlowNode for from sys import * |
|
||||
| test.py | 33 | ControlFlowNode for ImportExpr | Module socket | ControlFlowNode for ImportExpr |
|
||||
| test.py | 34 | ControlFlowNode for timeout | builtin-class socket.timeout | ControlFlowNode for from _socket import * |
|
||||
| x.py | 2 | ControlFlowNode for ImportExpr | Module sys | ControlFlowNode for ImportExpr |
|
||||
@@ -0,0 +1,9 @@
|
||||
import python
|
||||
|
||||
from int line, ControlFlowNode f, Object o, ControlFlowNode orig
|
||||
where
|
||||
not f.getLocation().getFile().inStdlib() and
|
||||
f.refersTo(o, orig) and
|
||||
line = f.getLocation().getStartLine() and
|
||||
line != 0
|
||||
select f.getLocation().getFile().getShortName(), line, f.toString(), o.toString(), orig.toString()
|
||||
@@ -0,0 +1,57 @@
|
||||
| __init__.py | 1 | ControlFlowNode for ImportExpr | Module package.module | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 2 | ControlFlowNode for ImportMember | Function module | builtin-class function | ControlFlowNode for FunctionExpr |
|
||||
| __init__.py | 2 | ControlFlowNode for module | Function module | builtin-class function | ControlFlowNode for FunctionExpr |
|
||||
| __init__.py | 4 | ControlFlowNode for ImportExpr | Module package | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 4 | ControlFlowNode for ImportMember | Module package.module2 | builtin-class module | Entry node for Module package.module2 |
|
||||
| __init__.py | 4 | ControlFlowNode for module3 | Module package.module2 | builtin-class module | Entry node for Module package.module2 |
|
||||
| __init__.py | 5 | ControlFlowNode for IntegerLiteral | int 7 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| __init__.py | 5 | ControlFlowNode for module2 | int 7 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| __init__.py | 6 | ControlFlowNode for ImportExpr | Module package | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 6 | ControlFlowNode for ImportMember | int 7 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| __init__.py | 6 | ControlFlowNode for module4 | int 7 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| __init__.py | 7 | ControlFlowNode for ImportExpr | Module package | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 7 | ControlFlowNode for ImportMember | Module package.module2 | builtin-class module | Entry node for Module package.module2 |
|
||||
| __init__.py | 7 | ControlFlowNode for module5 | Module package.module2 | builtin-class module | Entry node for Module package.module2 |
|
||||
| __init__.py | 8 | ControlFlowNode for ImportExpr | Module package | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| __init__.py | 8 | ControlFlowNode for ImportMember | Module package.moduleX | builtin-class module | Entry node for Module package.moduleX |
|
||||
| __init__.py | 8 | ControlFlowNode for moduleX | Module package.moduleX | builtin-class module | Entry node for Module package.moduleX |
|
||||
| module2.py | 1 | ControlFlowNode for IntegerLiteral | int 0 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| module2.py | 1 | ControlFlowNode for x | int 0 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| module.py | 2 | ControlFlowNode for FunctionExpr | Function module | builtin-class function | ControlFlowNode for FunctionExpr |
|
||||
| module.py | 2 | ControlFlowNode for module | Function module | builtin-class function | ControlFlowNode for FunctionExpr |
|
||||
| moduleX.py | 1 | ControlFlowNode for ClassExpr | class Y | builtin-class type | ControlFlowNode for ClassExpr |
|
||||
| moduleX.py | 1 | ControlFlowNode for Y | class Y | builtin-class type | ControlFlowNode for ClassExpr |
|
||||
| moduleX.py | 1 | ControlFlowNode for object | builtin-class object | builtin-class type | ControlFlowNode for object |
|
||||
| test.py | 1 | ControlFlowNode for ImportExpr | Module package | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| test.py | 2 | ControlFlowNode for ImportMember | Function module | builtin-class function | ControlFlowNode for FunctionExpr |
|
||||
| test.py | 2 | ControlFlowNode for module | Function module | builtin-class function | ControlFlowNode for FunctionExpr |
|
||||
| test.py | 4 | ControlFlowNode for ImportExpr | Module package | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| test.py | 5 | ControlFlowNode for ImportMember | Module package.x | builtin-class module | Entry node for Module package.x |
|
||||
| test.py | 5 | ControlFlowNode for x | Module package.x | builtin-class module | Entry node for Module package.x |
|
||||
| test.py | 8 | ControlFlowNode for C | class C | builtin-class type | ControlFlowNode for ClassExpr |
|
||||
| test.py | 8 | ControlFlowNode for ClassExpr | class C | builtin-class type | ControlFlowNode for ClassExpr |
|
||||
| test.py | 8 | ControlFlowNode for object | builtin-class object | builtin-class type | ControlFlowNode for object |
|
||||
| test.py | 10 | ControlFlowNode for ImportExpr | Module package | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| test.py | 10 | ControlFlowNode for ImportMember | int 7 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| test.py | 10 | ControlFlowNode for module2 | int 7 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| test.py | 12 | ControlFlowNode for FunctionExpr | Function f | builtin-class function | ControlFlowNode for FunctionExpr |
|
||||
| test.py | 12 | ControlFlowNode for f | Function f | builtin-class function | ControlFlowNode for FunctionExpr |
|
||||
| test.py | 13 | ControlFlowNode for ImportExpr | Module package | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| test.py | 13 | ControlFlowNode for ImportMember | Module package.x | builtin-class module | Entry node for Module package.x |
|
||||
| test.py | 13 | ControlFlowNode for x | Module package.x | builtin-class module | Entry node for Module package.x |
|
||||
| test.py | 15 | ControlFlowNode for ImportExpr | Module package | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| test.py | 15 | ControlFlowNode for ImportMember | Module package.moduleX | builtin-class module | Entry node for Module package.moduleX |
|
||||
| test.py | 15 | ControlFlowNode for moduleX | Module package.moduleX | builtin-class module | Entry node for Module package.moduleX |
|
||||
| test.py | 16 | ControlFlowNode for Attribute | class Y | builtin-class type | ControlFlowNode for ClassExpr |
|
||||
| test.py | 16 | ControlFlowNode for moduleX | Module package.moduleX | builtin-class module | Entry node for Module package.moduleX |
|
||||
| test.py | 19 | ControlFlowNode for ImportExpr | Module tty | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| test.py | 19 | ControlFlowNode for tty | Module tty | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| test.py | 22 | ControlFlowNode for Attribute | Builtin-function exc_info | builtin-class builtin_function_or_method | ControlFlowNode for from sys import * |
|
||||
| test.py | 22 | ControlFlowNode for x | Module package.x | builtin-class module | Entry node for Module package.x |
|
||||
| test.py | 24 | ControlFlowNode for IntegerLiteral | int 0 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| test.py | 24 | ControlFlowNode for argv | int 0 | builtin-class int | ControlFlowNode for IntegerLiteral |
|
||||
| test.py | 27 | ControlFlowNode for ImportExpr | Module sys | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| test.py | 31 | ControlFlowNode for argv | list object | builtin-class list | ControlFlowNode for from sys import * |
|
||||
| test.py | 33 | ControlFlowNode for ImportExpr | Module socket | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
| test.py | 34 | ControlFlowNode for timeout | builtin-class socket.timeout | builtin-class type | ControlFlowNode for from _socket import * |
|
||||
| x.py | 2 | ControlFlowNode for ImportExpr | Module sys | builtin-class module | ControlFlowNode for ImportExpr |
|
||||
@@ -0,0 +1,10 @@
|
||||
import python
|
||||
|
||||
from int line, ControlFlowNode f, Object o, ClassObject cls, ControlFlowNode orig
|
||||
where
|
||||
not f.getLocation().getFile().inStdlib() and
|
||||
f.refersTo(o, cls, orig) and
|
||||
line = f.getLocation().getStartLine() and
|
||||
line != 0
|
||||
select f.getLocation().getFile().getShortName(), line, f.toString(), o.toString(), cls.toString(),
|
||||
orig.toString()
|
||||
1
python/ql/test/3/library-tests/PointsTo/imports/options
Normal file
1
python/ql/test/3/library-tests/PointsTo/imports/options
Normal file
@@ -0,0 +1 @@
|
||||
semmle-extractor-options: --lang=3 --max-import-depth=2 -r package
|
||||
@@ -0,0 +1,15 @@
|
||||
from .module \
|
||||
import module
|
||||
|
||||
from . import module2 as module3
|
||||
module2 = 7
|
||||
from . import module2 as module4
|
||||
from . import module3 as module5
|
||||
from package import moduleX
|
||||
|
||||
#We should now have:
|
||||
#module2 = 7
|
||||
#module3 = package.module2
|
||||
#module4 = 7
|
||||
#module5 = package.module2
|
||||
#moduleX = package.moduleX
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
def module(args):
|
||||
pass
|
||||
@@ -0,0 +1 @@
|
||||
x = 0
|
||||
@@ -0,0 +1,2 @@
|
||||
class Y(object):
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
from sys import *
|
||||
34
python/ql/test/3/library-tests/PointsTo/imports/test.py
Normal file
34
python/ql/test/3/library-tests/PointsTo/imports/test.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from package \
|
||||
import module
|
||||
|
||||
from package \
|
||||
import x
|
||||
#Should work correctly in nested scopes as well.
|
||||
|
||||
class C(object):
|
||||
|
||||
from package import module2
|
||||
|
||||
def f(self):
|
||||
from package import x
|
||||
|
||||
from package import moduleX
|
||||
moduleX.Y
|
||||
|
||||
#A small stdlib module to test version handling.
|
||||
import tty
|
||||
|
||||
#Check imports of builtin-objects using import * with no corresponding variable.
|
||||
x.exc_info
|
||||
|
||||
argv = 0
|
||||
|
||||
try:
|
||||
from sys import *
|
||||
except:
|
||||
pass
|
||||
|
||||
argv
|
||||
|
||||
from socket import *
|
||||
timeout
|
||||
@@ -0,0 +1,5 @@
|
||||
| file://:0:0:0:0 | Module sys | isUsedAsModule |
|
||||
| imported.py:0:0:0:0 | Module imported | isUsedAsModule |
|
||||
| main.py:0:0:0:0 | Module main | isUsedAsScript |
|
||||
| myscript.py:0:0:0:0 | Script myscript | isUsedAsScript |
|
||||
| script:0:0:0:0 | Script script | isUsedAsScript |
|
||||
16
python/ql/test/3/library-tests/modules/usage/ModuleUsage.ql
Normal file
16
python/ql/test/3/library-tests/modules/usage/ModuleUsage.ql
Normal file
@@ -0,0 +1,16 @@
|
||||
import python
|
||||
|
||||
from ModuleValue mv, string usage
|
||||
where
|
||||
// builtin module has different name in Python 2 and 3
|
||||
not mv = Module::builtinModule() and
|
||||
(
|
||||
mv.isUsedAsModule() and usage = "isUsedAsModule"
|
||||
or
|
||||
mv.isUsedAsScript() and usage = "isUsedAsScript"
|
||||
or
|
||||
not mv.isUsedAsModule() and
|
||||
not mv.isUsedAsScript() and
|
||||
usage = "<UNKNOWN>"
|
||||
)
|
||||
select mv, usage
|
||||
6
python/ql/test/3/library-tests/modules/usage/imported.py
Normal file
6
python/ql/test/3/library-tests/modules/usage/imported.py
Normal file
@@ -0,0 +1,6 @@
|
||||
def func():
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("I could have done something interesting...")
|
||||
print("but I didn't")
|
||||
5
python/ql/test/3/library-tests/modules/usage/main.py
Normal file
5
python/ql/test/3/library-tests/modules/usage/main.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import imported
|
||||
|
||||
if __name__ == "__main__":
|
||||
imported.func()
|
||||
print('Done')
|
||||
3
python/ql/test/3/library-tests/modules/usage/myscript.py
Executable file
3
python/ql/test/3/library-tests/modules/usage/myscript.py
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
print("I'm actually a script you see ;)")
|
||||
1
python/ql/test/3/library-tests/modules/usage/options
Normal file
1
python/ql/test/3/library-tests/modules/usage/options
Normal file
@@ -0,0 +1 @@
|
||||
semmle-extractor-options: --lang=3 -F script
|
||||
3
python/ql/test/3/library-tests/modules/usage/script
Executable file
3
python/ql/test/3/library-tests/modules/usage/script
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
print('Under construction :)')
|
||||
Reference in New Issue
Block a user