mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Python: Add copy of internal Python 2 tests
These are mostly extractor tests, which now live in `2/extractor-tests`, and a single library tests that was added to the existing directory.
This commit is contained in:
1
python/ql/test/2/extractor-tests/ellipsis/Test.expected
Normal file
1
python/ql/test/2/extractor-tests/ellipsis/Test.expected
Normal file
@@ -0,0 +1 @@
|
||||
| 2 |
|
||||
4
python/ql/test/2/extractor-tests/ellipsis/Test.ql
Normal file
4
python/ql/test/2/extractor-tests/ellipsis/Test.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
|
||||
select count(Ellipsis e)
|
||||
6
python/ql/test/2/extractor-tests/ellipsis/test.py
Normal file
6
python/ql/test/2/extractor-tests/ellipsis/test.py
Normal file
@@ -0,0 +1,6 @@
|
||||
a = {}
|
||||
a[...] = 1
|
||||
b = a[
|
||||
...]
|
||||
|
||||
print(b)
|
||||
23
python/ql/test/2/extractor-tests/exec/successors.expected
Normal file
23
python/ql/test/2/extractor-tests/exec/successors.expected
Normal file
@@ -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 |
|
||||
14
python/ql/test/2/extractor-tests/exec/successors.ql
Normal file
14
python/ql/test/2/extractor-tests/exec/successors.ql
Normal file
@@ -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
|
||||
3
python/ql/test/2/extractor-tests/exec/test.py
Normal file
3
python/ql/test/2/extractor-tests/exec/test.py
Normal file
@@ -0,0 +1,3 @@
|
||||
def f(x):
|
||||
exec("raise thing")
|
||||
return x
|
||||
5
python/ql/test/2/extractor-tests/exec/unicode.py
Normal file
5
python/ql/test/2/extractor-tests/exec/unicode.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
def f(x):
|
||||
exec("raise thing")
|
||||
return x
|
||||
2
python/ql/test/2/extractor-tests/hidden/options
Normal file
2
python/ql/test/2/extractor-tests/hidden/options
Normal file
@@ -0,0 +1,2 @@
|
||||
semmle-extractor-options: -R . -p . --filter exclude:**/src_archive/**
|
||||
|
||||
4
python/ql/test/2/extractor-tests/hidden/test.expected
Normal file
4
python/ql/test/2/extractor-tests/hidden/test.expected
Normal file
@@ -0,0 +1,4 @@
|
||||
| folder/module.py |
|
||||
| package |
|
||||
| package/__init__.py |
|
||||
| package/module.py |
|
||||
5
python/ql/test/2/extractor-tests/hidden/test.ql
Normal file
5
python/ql/test/2/extractor-tests/hidden/test.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import python
|
||||
|
||||
from Container f
|
||||
where exists(Module m | m.getPath() = f)
|
||||
select f.toString()
|
||||
1
python/ql/test/2/extractor-tests/import_depth/options
Normal file
1
python/ql/test/2/extractor-tests/import_depth/options
Normal file
@@ -0,0 +1 @@
|
||||
semmle-extractor-options: --lang=2 --max-import-depth=1
|
||||
@@ -0,0 +1,4 @@
|
||||
| Module package |
|
||||
| Module package.__init__ |
|
||||
| Module sys |
|
||||
| Module test |
|
||||
1
python/ql/test/2/extractor-tests/import_depth/test.py
Normal file
1
python/ql/test/2/extractor-tests/import_depth/test.py
Normal file
@@ -0,0 +1 @@
|
||||
import package
|
||||
6
python/ql/test/2/extractor-tests/import_depth/test.ql
Normal file
6
python/ql/test/2/extractor-tests/import_depth/test.ql
Normal file
@@ -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()
|
||||
6
python/ql/test/2/extractor-tests/multibyte/Test.expected
Normal file
6
python/ql/test/2/extractor-tests/multibyte/Test.expected
Normal file
@@ -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 |
|
||||
4
python/ql/test/2/extractor-tests/multibyte/Test.ql
Normal file
4
python/ql/test/2/extractor-tests/multibyte/Test.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from StrConst s
|
||||
select s, s.getText()
|
||||
1
python/ql/test/2/extractor-tests/multibyte/options
Normal file
1
python/ql/test/2/extractor-tests/multibyte/options
Normal file
@@ -0,0 +1 @@
|
||||
automatic_locations: true
|
||||
4
python/ql/test/2/extractor-tests/multibyte/test.py
Normal file
4
python/ql/test/2/extractor-tests/multibyte/test.py
Normal file
@@ -0,0 +1,4 @@
|
||||
#coding=utf8
|
||||
|
||||
b"đłe¶ŋ¶łŋ" + b"hi" + b"\n"
|
||||
u"đłe¶ŋ¶łŋ" + u"hi" + u"\n"
|
||||
@@ -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 |
|
||||
17
python/ql/test/2/extractor-tests/normalise/Numbers.ql
Normal file
17
python/ql/test/2/extractor-tests/normalise/Numbers.ql
Normal file
@@ -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()
|
||||
23
python/ql/test/2/extractor-tests/normalise/test.py
Normal file
23
python/ql/test/2/extractor-tests/normalise/test.py
Normal file
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
| 1 |
|
||||
5
python/ql/test/2/extractor-tests/object_hash/Success.ql
Normal file
5
python/ql/test/2/extractor-tests/object_hash/Success.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
import python
|
||||
|
||||
where exists(theSysModuleObject())
|
||||
select 1
|
||||
1
python/ql/test/2/extractor-tests/object_hash/test.py
Normal file
1
python/ql/test/2/extractor-tests/object_hash/test.py
Normal file
@@ -0,0 +1 @@
|
||||
import cStringIO
|
||||
@@ -0,0 +1 @@
|
||||
| test.py:1:1:1:6 | Compare |
|
||||
@@ -0,0 +1 @@
|
||||
1 <> 2
|
||||
@@ -0,0 +1,3 @@
|
||||
import python
|
||||
|
||||
select any(Compare o)
|
||||
1
python/ql/test/2/extractor-tests/options
Normal file
1
python/ql/test/2/extractor-tests/options
Normal file
@@ -0,0 +1 @@
|
||||
automatic_locations: true
|
||||
@@ -0,0 +1 @@
|
||||
| Module test | test |
|
||||
5
python/ql/test/2/extractor-tests/syntax_error/Modules.ql
Normal file
5
python/ql/test/2/extractor-tests/syntax_error/Modules.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
import python
|
||||
|
||||
from Module m
|
||||
select m.toString(), m.getName()
|
||||
@@ -0,0 +1 @@
|
||||
| Syntax Error |
|
||||
4
python/ql/test/2/extractor-tests/syntax_error/Test.ql
Normal file
4
python/ql/test/2/extractor-tests/syntax_error/Test.ql
Normal file
@@ -0,0 +1,4 @@
|
||||
import python
|
||||
|
||||
from SyntaxError s
|
||||
select s.toString()
|
||||
2
python/ql/test/2/extractor-tests/syntax_error/test.py
Normal file
2
python/ql/test/2/extractor-tests/syntax_error/test.py
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
Not python at all :(
|
||||
@@ -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 |
|
||||
@@ -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()
|
||||
5
python/ql/test/2/library-tests/locations2.7plus/test.py
Normal file
5
python/ql/test/2/library-tests/locations2.7plus/test.py
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
{k:v for k,v in enumerate(y)}
|
||||
{ 1, 2, 3, 4 }
|
||||
{ i for i in y }
|
||||
|
||||
Reference in New Issue
Block a user