diff --git a/python/ql/test/2/extractor-tests/ellipsis/Test.expected b/python/ql/test/2/extractor-tests/ellipsis/Test.expected new file mode 100644 index 00000000000..a882f18620b --- /dev/null +++ b/python/ql/test/2/extractor-tests/ellipsis/Test.expected @@ -0,0 +1 @@ +| 2 | diff --git a/python/ql/test/2/extractor-tests/ellipsis/Test.ql b/python/ql/test/2/extractor-tests/ellipsis/Test.ql new file mode 100644 index 00000000000..66512646210 --- /dev/null +++ b/python/ql/test/2/extractor-tests/ellipsis/Test.ql @@ -0,0 +1,4 @@ +import python + + +select count(Ellipsis e) \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/ellipsis/test.py b/python/ql/test/2/extractor-tests/ellipsis/test.py new file mode 100644 index 00000000000..e43c09f2527 --- /dev/null +++ b/python/ql/test/2/extractor-tests/ellipsis/test.py @@ -0,0 +1,6 @@ +a = {} +a[...] = 1 +b = a[ + ...] + +print(b) diff --git a/python/ql/test/2/extractor-tests/exec/successors.expected b/python/ql/test/2/extractor-tests/exec/successors.expected new file mode 100644 index 00000000000..fb159095eba --- /dev/null +++ b/python/ql/test/2/extractor-tests/exec/successors.expected @@ -0,0 +1,23 @@ +| test.py | 0 | Entry node for Module test | 1 | ControlFlowNode for FunctionExpr | normal | +| test.py | 1 | ControlFlowNode for FunctionExpr | 1 | ControlFlowNode for f | normal | +| test.py | 1 | ControlFlowNode for f | 0 | Exit node for Module test | normal | +| test.py | 1 | ControlFlowNode for x | 2 | ControlFlowNode for exec | normal | +| test.py | 1 | Entry node for Function f | 1 | ControlFlowNode for x | normal | +| test.py | 2 | ControlFlowNode for Str | 2 | ControlFlowNode for exec() | normal | +| test.py | 2 | ControlFlowNode for exec | 2 | ControlFlowNode for Str | normal | +| test.py | 2 | ControlFlowNode for exec() | 3 | ControlFlowNode for x | normal | +| test.py | 3 | ControlFlowNode for Return | 1 | Exit node for Function f | normal | +| test.py | 3 | ControlFlowNode for x | 3 | ControlFlowNode for Return | normal | +| unicode.py | 0 | Entry node for Module unicode | 1 | ControlFlowNode for ImportExpr | normal | +| unicode.py | 1 | ControlFlowNode for ImportExpr | 1 | ControlFlowNode for ImportMember | normal | +| unicode.py | 1 | ControlFlowNode for ImportMember | 1 | ControlFlowNode for unicode_literals | normal | +| unicode.py | 1 | ControlFlowNode for unicode_literals | 3 | ControlFlowNode for FunctionExpr | normal | +| unicode.py | 3 | ControlFlowNode for FunctionExpr | 3 | ControlFlowNode for f | normal | +| unicode.py | 3 | ControlFlowNode for f | 0 | Exit node for Module unicode | normal | +| unicode.py | 3 | ControlFlowNode for x | 4 | ControlFlowNode for exec | normal | +| unicode.py | 3 | Entry node for Function f | 3 | ControlFlowNode for x | normal | +| unicode.py | 4 | ControlFlowNode for Str | 4 | ControlFlowNode for exec() | normal | +| unicode.py | 4 | ControlFlowNode for exec | 4 | ControlFlowNode for Str | normal | +| unicode.py | 4 | ControlFlowNode for exec() | 5 | ControlFlowNode for x | normal | +| unicode.py | 5 | ControlFlowNode for Return | 3 | Exit node for Function f | normal | +| unicode.py | 5 | ControlFlowNode for x | 5 | ControlFlowNode for Return | normal | diff --git a/python/ql/test/2/extractor-tests/exec/successors.ql b/python/ql/test/2/extractor-tests/exec/successors.ql new file mode 100644 index 00000000000..14b20b0175f --- /dev/null +++ b/python/ql/test/2/extractor-tests/exec/successors.ql @@ -0,0 +1,14 @@ + +import python + +from ControlFlowNode p, ControlFlowNode s, string kind, string filename + +where p.getASuccessor() = s and +( + p.getAnExceptionalSuccessor() = s and kind = "exception" + or + not p.getAnExceptionalSuccessor() = s and kind = "normal" +) and filename = p.getLocation().getFile().getShortName() and +not filename = "__future__.py" + +select filename, p.getLocation().getStartLine(), p.toString(), s.getLocation().getStartLine(), s.toString(), kind diff --git a/python/ql/test/2/extractor-tests/exec/test.py b/python/ql/test/2/extractor-tests/exec/test.py new file mode 100644 index 00000000000..f972d9db7b1 --- /dev/null +++ b/python/ql/test/2/extractor-tests/exec/test.py @@ -0,0 +1,3 @@ +def f(x): + exec("raise thing") + return x diff --git a/python/ql/test/2/extractor-tests/exec/unicode.py b/python/ql/test/2/extractor-tests/exec/unicode.py new file mode 100644 index 00000000000..33c3fbe99f8 --- /dev/null +++ b/python/ql/test/2/extractor-tests/exec/unicode.py @@ -0,0 +1,5 @@ +from __future__ import unicode_literals + +def f(x): + exec("raise thing") + return x diff --git a/python/ql/test/2/extractor-tests/hidden/.hidden/inner/test.py b/python/ql/test/2/extractor-tests/hidden/.hidden/inner/test.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/ql/test/2/extractor-tests/hidden/.hidden/module.py b/python/ql/test/2/extractor-tests/hidden/.hidden/module.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/ql/test/2/extractor-tests/hidden/folder/module.py b/python/ql/test/2/extractor-tests/hidden/folder/module.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/ql/test/2/extractor-tests/hidden/options b/python/ql/test/2/extractor-tests/hidden/options new file mode 100644 index 00000000000..86ff17933db --- /dev/null +++ b/python/ql/test/2/extractor-tests/hidden/options @@ -0,0 +1,2 @@ +semmle-extractor-options: -R . -p . --filter exclude:**/src_archive/** + diff --git a/python/ql/test/2/extractor-tests/hidden/package/__init__.py b/python/ql/test/2/extractor-tests/hidden/package/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/ql/test/2/extractor-tests/hidden/package/module.py b/python/ql/test/2/extractor-tests/hidden/package/module.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/ql/test/2/extractor-tests/hidden/test.expected b/python/ql/test/2/extractor-tests/hidden/test.expected new file mode 100644 index 00000000000..ca72363d8f0 --- /dev/null +++ b/python/ql/test/2/extractor-tests/hidden/test.expected @@ -0,0 +1,4 @@ +| folder/module.py | +| package | +| package/__init__.py | +| package/module.py | diff --git a/python/ql/test/2/extractor-tests/hidden/test.ql b/python/ql/test/2/extractor-tests/hidden/test.ql new file mode 100644 index 00000000000..4c405704d6b --- /dev/null +++ b/python/ql/test/2/extractor-tests/hidden/test.ql @@ -0,0 +1,5 @@ +import python + +from Container f +where exists(Module m | m.getPath() = f) +select f.toString() diff --git a/python/ql/test/2/extractor-tests/import_depth/options b/python/ql/test/2/extractor-tests/import_depth/options new file mode 100644 index 00000000000..82ea79d8fac --- /dev/null +++ b/python/ql/test/2/extractor-tests/import_depth/options @@ -0,0 +1 @@ +semmle-extractor-options: --lang=2 --max-import-depth=1 diff --git a/python/ql/test/2/extractor-tests/import_depth/package/__init__.py b/python/ql/test/2/extractor-tests/import_depth/package/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/ql/test/2/extractor-tests/import_depth/package/x.py b/python/ql/test/2/extractor-tests/import_depth/package/x.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/ql/test/2/extractor-tests/import_depth/test.expected b/python/ql/test/2/extractor-tests/import_depth/test.expected new file mode 100644 index 00000000000..caa5c458207 --- /dev/null +++ b/python/ql/test/2/extractor-tests/import_depth/test.expected @@ -0,0 +1,4 @@ +| Module package | +| Module package.__init__ | +| Module sys | +| Module test | diff --git a/python/ql/test/2/extractor-tests/import_depth/test.py b/python/ql/test/2/extractor-tests/import_depth/test.py new file mode 100644 index 00000000000..234bf707532 --- /dev/null +++ b/python/ql/test/2/extractor-tests/import_depth/test.py @@ -0,0 +1 @@ +import package \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/import_depth/test.ql b/python/ql/test/2/extractor-tests/import_depth/test.ql new file mode 100644 index 00000000000..3e10834ee53 --- /dev/null +++ b/python/ql/test/2/extractor-tests/import_depth/test.ql @@ -0,0 +1,6 @@ +import python + +from ModuleObject m +/* Exclude the builtins module as it has a different name under 2 and 3. */ +where not m = theBuiltinModuleObject() +select m.toString() \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/multibyte/Test.expected b/python/ql/test/2/extractor-tests/multibyte/Test.expected new file mode 100644 index 00000000000..dc3e84e5419 --- /dev/null +++ b/python/ql/test/2/extractor-tests/multibyte/Test.expected @@ -0,0 +1,6 @@ +| test.py:3:1:3:11 | Str | \u0111\u0142e\u00b6\u014b\u00b6\u0142\u014b | +| test.py:3:15:3:19 | Str | hi | +| test.py:3:23:3:27 | Str | \n | +| test.py:4:1:4:11 | Str | \u0111\u0142e\u00b6\u014b\u00b6\u0142\u014b | +| test.py:4:15:4:19 | Str | hi | +| test.py:4:23:4:27 | Str | \n | diff --git a/python/ql/test/2/extractor-tests/multibyte/Test.ql b/python/ql/test/2/extractor-tests/multibyte/Test.ql new file mode 100644 index 00000000000..954bcabff7c --- /dev/null +++ b/python/ql/test/2/extractor-tests/multibyte/Test.ql @@ -0,0 +1,4 @@ +import python + +from StrConst s +select s, s.getText() \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/multibyte/options b/python/ql/test/2/extractor-tests/multibyte/options new file mode 100644 index 00000000000..25b9f96abe1 --- /dev/null +++ b/python/ql/test/2/extractor-tests/multibyte/options @@ -0,0 +1 @@ +automatic_locations: true \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/multibyte/test.py b/python/ql/test/2/extractor-tests/multibyte/test.py new file mode 100644 index 00000000000..3f20a7ba23a --- /dev/null +++ b/python/ql/test/2/extractor-tests/multibyte/test.py @@ -0,0 +1,4 @@ +#coding=utf8 + +b"đłe¶ŋ¶łŋ" + b"hi" + b"\n" +u"đłe¶ŋ¶łŋ" + u"hi" + u"\n" diff --git a/python/ql/test/2/extractor-tests/normalise/Numbers.expected b/python/ql/test/2/extractor-tests/normalise/Numbers.expected new file mode 100644 index 00000000000..c8b01df0e40 --- /dev/null +++ b/python/ql/test/2/extractor-tests/normalise/Numbers.expected @@ -0,0 +1,7 @@ +| int 0 | 0 | +| int 1 | 1 | +| int 2 | 2 | +| int 123745 | 123745 | +| int 268435455 | 268435455 | +| int 17216961135462248174 | 17216961135462248174 | +| int 100000000000000000000000000000000000000000000 | 100000000000000000000000000000000000000000000 | diff --git a/python/ql/test/2/extractor-tests/normalise/Numbers.ql b/python/ql/test/2/extractor-tests/normalise/Numbers.ql new file mode 100644 index 00000000000..eab924e6d40 --- /dev/null +++ b/python/ql/test/2/extractor-tests/normalise/Numbers.ql @@ -0,0 +1,17 @@ +/** + * Much of the QL library handling integral values assumes that + * equivalence of the DB entities implies equivalence of the + * Python object and vice-versa. + * In Python 2, 1L == 1, which can cause problems, so we + * normalise all longs to ints. + */ + +import python + +from NumericObject n +where +exists(IntegerLiteral i | + i.getLiteralObject() = n | + i.getEnclosingModule().getFile().getShortName() = "test.py" +) +select n.toString(), n.repr() diff --git a/python/ql/test/2/extractor-tests/normalise/test.py b/python/ql/test/2/extractor-tests/normalise/test.py new file mode 100644 index 00000000000..04096785860 --- /dev/null +++ b/python/ql/test/2/extractor-tests/normalise/test.py @@ -0,0 +1,23 @@ + +#ints +0 +0L +1 +1L +2 +2L +123745 +123745L + +0xfffffff +0xfffffffL + +#Avoid values between 32 and 64 bits, as long is 32 bits on windows and 64 bits on 64 bit linux machines. + + + +#longs +0xeeeeeeeeeeeeeeee +0xeeeeeeeeeeeeeeeeL +100000000000000000000000000000000000000000000 +100000000000000000000000000000000000000000000L diff --git a/python/ql/test/2/extractor-tests/object_hash/Success.expected b/python/ql/test/2/extractor-tests/object_hash/Success.expected new file mode 100644 index 00000000000..4b74744d8be --- /dev/null +++ b/python/ql/test/2/extractor-tests/object_hash/Success.expected @@ -0,0 +1 @@ +| 1 | \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/object_hash/Success.ql b/python/ql/test/2/extractor-tests/object_hash/Success.ql new file mode 100644 index 00000000000..1834d8fe394 --- /dev/null +++ b/python/ql/test/2/extractor-tests/object_hash/Success.ql @@ -0,0 +1,5 @@ + +import python + +where exists(theSysModuleObject()) +select 1 diff --git a/python/ql/test/2/extractor-tests/object_hash/test.py b/python/ql/test/2/extractor-tests/object_hash/test.py new file mode 100644 index 00000000000..f3e6c46abf5 --- /dev/null +++ b/python/ql/test/2/extractor-tests/object_hash/test.py @@ -0,0 +1 @@ +import cStringIO diff --git a/python/ql/test/2/extractor-tests/old_style_disequality/test.expected b/python/ql/test/2/extractor-tests/old_style_disequality/test.expected new file mode 100644 index 00000000000..ff44728f13a --- /dev/null +++ b/python/ql/test/2/extractor-tests/old_style_disequality/test.expected @@ -0,0 +1 @@ +| test.py:1:1:1:6 | Compare | diff --git a/python/ql/test/2/extractor-tests/old_style_disequality/test.py b/python/ql/test/2/extractor-tests/old_style_disequality/test.py new file mode 100644 index 00000000000..86d0b306fd1 --- /dev/null +++ b/python/ql/test/2/extractor-tests/old_style_disequality/test.py @@ -0,0 +1 @@ +1 <> 2 diff --git a/python/ql/test/2/extractor-tests/old_style_disequality/test.ql b/python/ql/test/2/extractor-tests/old_style_disequality/test.ql new file mode 100644 index 00000000000..3df6ad0c7af --- /dev/null +++ b/python/ql/test/2/extractor-tests/old_style_disequality/test.ql @@ -0,0 +1,3 @@ +import python + +select any(Compare o) diff --git a/python/ql/test/2/extractor-tests/options b/python/ql/test/2/extractor-tests/options new file mode 100644 index 00000000000..25b9f96abe1 --- /dev/null +++ b/python/ql/test/2/extractor-tests/options @@ -0,0 +1 @@ +automatic_locations: true \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/syntax_error/Modules.expected b/python/ql/test/2/extractor-tests/syntax_error/Modules.expected new file mode 100644 index 00000000000..1b7be371db1 --- /dev/null +++ b/python/ql/test/2/extractor-tests/syntax_error/Modules.expected @@ -0,0 +1 @@ +| Module test | test | \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/syntax_error/Modules.ql b/python/ql/test/2/extractor-tests/syntax_error/Modules.ql new file mode 100644 index 00000000000..66b04256568 --- /dev/null +++ b/python/ql/test/2/extractor-tests/syntax_error/Modules.ql @@ -0,0 +1,5 @@ + +import python + +from Module m +select m.toString(), m.getName() diff --git a/python/ql/test/2/extractor-tests/syntax_error/Test.expected b/python/ql/test/2/extractor-tests/syntax_error/Test.expected new file mode 100644 index 00000000000..b075bff9282 --- /dev/null +++ b/python/ql/test/2/extractor-tests/syntax_error/Test.expected @@ -0,0 +1 @@ +| Syntax Error | \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/syntax_error/Test.ql b/python/ql/test/2/extractor-tests/syntax_error/Test.ql new file mode 100644 index 00000000000..a65d66cfa2b --- /dev/null +++ b/python/ql/test/2/extractor-tests/syntax_error/Test.ql @@ -0,0 +1,4 @@ +import python + +from SyntaxError s +select s.toString() \ No newline at end of file diff --git a/python/ql/test/2/extractor-tests/syntax_error/test.py b/python/ql/test/2/extractor-tests/syntax_error/test.py new file mode 100644 index 00000000000..67cc65ddaca --- /dev/null +++ b/python/ql/test/2/extractor-tests/syntax_error/test.py @@ -0,0 +1,2 @@ + +Not python at all :( diff --git a/python/ql/test/2/library-tests/locations2.7plus/Locations.expected b/python/ql/test/2/library-tests/locations2.7plus/Locations.expected new file mode 100644 index 00000000000..25b023c96d0 --- /dev/null +++ b/python/ql/test/2/library-tests/locations2.7plus/Locations.expected @@ -0,0 +1,35 @@ +| Call | 2 | 17 | 2 | 28 | +| DictComp | 2 | 1 | 2 | 29 | +| ExprStmt | 2 | 1 | 2 | 29 | +| ExprStmt | 2 | 2 | 2 | 4 | +| ExprStmt | 3 | 1 | 3 | 14 | +| ExprStmt | 4 | 1 | 4 | 16 | +| ExprStmt | 4 | 3 | 4 | 3 | +| FastLocalsFunction | 2 | 1 | 2 | 29 | +| FastLocalsFunction | 4 | 1 | 4 | 16 | +| For | 2 | 1 | 2 | 29 | +| For | 4 | 1 | 4 | 16 | +| FunctionMetrics | 2 | 1 | 2 | 29 | +| FunctionMetrics | 4 | 1 | 4 | 16 | +| IntegerLiteral | 3 | 3 | 3 | 3 | +| IntegerLiteral | 3 | 6 | 3 | 6 | +| IntegerLiteral | 3 | 9 | 3 | 9 | +| IntegerLiteral | 3 | 12 | 3 | 12 | +| ModuleMetrics | 0 | 0 | 0 | 0 | +| Name | 2 | 1 | 2 | 29 | +| Name | 2 | 2 | 2 | 2 | +| Name | 2 | 4 | 2 | 4 | +| Name | 2 | 10 | 2 | 10 | +| Name | 2 | 12 | 2 | 12 | +| Name | 2 | 17 | 2 | 25 | +| Name | 2 | 27 | 2 | 27 | +| Name | 4 | 1 | 4 | 16 | +| Name | 4 | 3 | 4 | 3 | +| Name | 4 | 9 | 4 | 9 | +| Name | 4 | 14 | 4 | 14 | +| Set | 3 | 1 | 3 | 14 | +| SetComp | 4 | 1 | 4 | 16 | +| Tuple | 2 | 2 | 2 | 4 | +| Tuple | 2 | 10 | 2 | 12 | +| Yield | 2 | 2 | 2 | 4 | +| Yield | 4 | 3 | 4 | 3 | \ No newline at end of file diff --git a/python/ql/test/2/library-tests/locations2.7plus/Locations.ql b/python/ql/test/2/library-tests/locations2.7plus/Locations.ql new file mode 100644 index 00000000000..874eecbdb9f --- /dev/null +++ b/python/ql/test/2/library-tests/locations2.7plus/Locations.ql @@ -0,0 +1,6 @@ +import python + + +from AstNode ast, Location l +where ast.getLocation() = l +select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() \ No newline at end of file diff --git a/python/ql/test/2/library-tests/locations2.7plus/test.py b/python/ql/test/2/library-tests/locations2.7plus/test.py new file mode 100644 index 00000000000..a2648b5823b --- /dev/null +++ b/python/ql/test/2/library-tests/locations2.7plus/test.py @@ -0,0 +1,5 @@ + +{k:v for k,v in enumerate(y)} +{ 1, 2, 3, 4 } +{ i for i in y } +