Skip to content

Commit e45f6e9

Browse files
committed
Python: Add copy of extractor tests
These get to live next to the existing library and query tests, and are run as part of both the Python 2 and Python 3 language tests.
1 parent d5073df commit e45f6e9

File tree

182 files changed

+13695
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+13695
-0
lines changed

python/ql/test/extractor-tests/ast/Child.expected

Lines changed: 364 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import python
2+
import semmle.python.TestUtils
3+
4+
from AstNode p, AstNode c
5+
where p.getAChildNode() = c
6+
select compact_location(p), p.toString(), compact_location(c), c.toString()
7+
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
2+
@deco1
3+
@deco2()
4+
@deco3.attr1.attr2
5+
class C(Base):
6+
7+
def __init__(self):
8+
pass
9+
10+
@deco4.attr()
11+
def f():
12+
pass
13+
14+
def f(pos0, pos1, *args, **kwargs):
15+
pass
16+
17+
def simple_stmts():
18+
pass
19+
foo() ; del x; pass
20+
if thing:
21+
for a in b:
22+
pass
23+
#Expressions
24+
tmp = (
25+
yield 3,
26+
name,
27+
attr.attrname,
28+
a + b,
29+
3 & 4,
30+
3.0 * 4,
31+
a.b.c.d,
32+
a().b[c],
33+
lambda x: x+1,
34+
p or q and r ^ s,
35+
a < b > c in 5,
36+
{ 1 : y for z in x for y in z},
37+
{ (1, y) for z in x for y in z},
38+
[ y**2 for y in z ],
39+
[],
40+
{},
41+
(),
42+
(1,),
43+
)
44+
foo(1)
45+
foo(a=1)
46+
foo(1,2,*t)
47+
foo(1,a=1,*t)
48+
foo(1,a=1,*t,**d)
49+
f(**d)
50+
51+
def compound_stmts():
52+
if cond:
53+
return x
54+
else:
55+
raise y
56+
while True:
57+
if cond:
58+
break
59+
else:
60+
continue
61+
for x in y:
62+
pass
63+
with a as b, c as d:
64+
body
65+
try:
66+
t1
67+
except:
68+
e1
69+
try:
70+
t2
71+
except Exception:
72+
e2
73+
try:
74+
t3
75+
except Exception as ex:
76+
e3
77+
try:
78+
t4
79+
finally:
80+
f4
81+
try:
82+
t5
83+
except Exception as ex:
84+
e5
85+
finally:
86+
f5
87+
try:
88+
t6
89+
finally:
90+
try:
91+
t7
92+
finally:
93+
f7
94+
95+
#Unusual classdef
96+
class WhyUseParens():
97+
pass
98+
99+
#Annotations
100+
x: 1
101+
x: y
102+
x: {y[a][b]:z-q}
103+
x: f(1, d=3, *t)
104+
105+
106+
#f-strings with format specifier
107+
f'result: {value:0.2f}'
108+
f'result: {value:{width}.{precision}}'
109+
110+
111+
f"Too {'many' if alen > elen else 'few'} parameters for {cls};"
112+
#f" actual {alen}, expected {elen}"
113+
114+
#Backticks
115+
`backticks`
116+
`why, are, we, still, supporting, this in 2019`
117+
118+
119+
def numeric_literals():
120+
# Various corner cases for numeric literals
121+
tmp = (
122+
0b00010101011111111111L,
123+
1_1,
124+
0b1_1,
125+
0x1_1,
126+
0b_010,
127+
0x_010,
128+
0_0,
129+
009.,
130+
009e005,
131+
00123,
132+
0o77777777777L,
133+
0777777777777L,
134+
0o1_1,
135+
0o_010,
136+
1_2_3.4_5_6e7_8_9,
137+
0_0234j
138+
)
139+
140+
#Grammar ambiguity in extractor version 5.4
141+
print(f'{"foo"}')
142+
print(f"{"bar"}")
143+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| 22 | For |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
import python
3+
from AsyncFor a
4+
select a.getLocation().getStartLine(), a.toString()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| 23 | With |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
import python
3+
from AsyncWith aw
4+
select aw.getLocation().getStartLine(), aw.toString()
5+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| 25 | Await |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import python
2+
3+
from Await a
4+
select a.getLocation().getStartLine(), a.toString()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| test.py:2:1:2:13 | Function normal | no |
2+
| test.py:5:7:5:21 | Function is_async | yes |
3+
| test.py:8:1:8:20 | Function decorator | no |
4+
| test.py:12:1:12:11 | Function deco | no |
5+
| test.py:16:7:16:23 | Function deco_async | yes |
6+
| test.py:21:7:21:16 | Function foo | yes |
7+
| visit_trailer_fp.py:1:1:1:10 | Function foo | no |
8+
| visit_trailer_fp.py:4:1:4:12 | Function await | no |
9+
| visit_trailer_fp.py:7:1:7:15 | Function bar | no |

0 commit comments

Comments
 (0)