Skip to content

Commit 2871a66

Browse files
committed
refactor tests
1 parent 303fa4f commit 2871a66

5 files changed

Lines changed: 214 additions & 212 deletions

File tree

mypy/test/test_nativeparse.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@
5252
class NativeParserSuite(DataSuite):
5353
required_out_section = True
5454
base_path = "."
55-
files = ["native-parser.test"] if has_nativeparse else []
55+
files = (
56+
["native-parser.test", "native-parser-python311.test", "native-parser-python312.test"]
57+
if has_nativeparse
58+
else []
59+
)
5660

5761
def run_case(self, testcase: DataDrivenTestCase) -> None:
5862
test_parser(testcase)
@@ -77,6 +81,8 @@ def test_parser(testcase: DataDrivenTestCase) -> None:
7781

7882
if testcase.file.endswith("python310.test"):
7983
options.python_version = (3, 10)
84+
elif testcase.file.endswith("python311.test"):
85+
options.python_version = (3, 11)
8086
elif testcase.file.endswith("python312.test"):
8187
options.python_version = (3, 12)
8288
elif testcase.file.endswith("python313.test"):
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
-- Native parser test cases that target Python 3.11.
2+
3+
[case testTryExceptStar]
4+
try:
5+
x
6+
except* ValueError:
7+
y
8+
[out]
9+
MypyFile:1(
10+
TryStmt:1(
11+
Block:2(
12+
ExpressionStmt:2(
13+
NameExpr(x)))
14+
*
15+
NameExpr(ValueError)
16+
Block:4(
17+
ExpressionStmt:4(
18+
NameExpr(y)))))
19+
20+
[case testTryExceptStarWithVar]
21+
try:
22+
x
23+
except* Exception as e:
24+
y
25+
[out]
26+
MypyFile:1(
27+
TryStmt:1(
28+
Block:2(
29+
ExpressionStmt:2(
30+
NameExpr(x)))
31+
*
32+
NameExpr(Exception)
33+
NameExpr(e)
34+
Block:4(
35+
ExpressionStmt:4(
36+
NameExpr(y)))))
37+
38+
[case testTryMultipleExceptStar]
39+
try:
40+
x
41+
except* ValueError:
42+
y
43+
except* KeyError as e:
44+
z
45+
[out]
46+
MypyFile:1(
47+
TryStmt:1(
48+
Block:2(
49+
ExpressionStmt:2(
50+
NameExpr(x)))
51+
*
52+
NameExpr(ValueError)
53+
Block:4(
54+
ExpressionStmt:4(
55+
NameExpr(y)))
56+
NameExpr(KeyError)
57+
NameExpr(e)
58+
Block:6(
59+
ExpressionStmt:6(
60+
NameExpr(z)))))
61+
62+
[case testTryExceptStarElseFinally]
63+
try:
64+
x
65+
except* ValueError:
66+
y
67+
else:
68+
z
69+
finally:
70+
w
71+
[out]
72+
MypyFile:1(
73+
TryStmt:1(
74+
Block:2(
75+
ExpressionStmt:2(
76+
NameExpr(x)))
77+
*
78+
NameExpr(ValueError)
79+
Block:4(
80+
ExpressionStmt:4(
81+
NameExpr(y)))
82+
Else(
83+
ExpressionStmt:6(
84+
NameExpr(z)))
85+
Finally(
86+
ExpressionStmt:8(
87+
NameExpr(w)))))
88+
89+
[case testUnpackTypeInSignature]
90+
def f(*args: *Ts) -> None:
91+
pass
92+
[out]
93+
MypyFile:1(
94+
FuncDef:1(
95+
f
96+
def (*args: *Ts?) -> None?
97+
VarArg(
98+
Var(args))
99+
Block:2(
100+
PassStmt:2())))
101+
102+
[case testUnpackTypeInTuple]
103+
x: tuple[int, *Ts, str]
104+
[out]
105+
MypyFile:1(
106+
AssignmentStmt:1(
107+
NameExpr(x)
108+
TempNode:1(
109+
Any)
110+
tuple?[int?, *Ts?, str?]))
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
-- Native parser test cases that target Python 3.12.
2+
3+
[case testPEP695TypeAlias]
4+
# comment
5+
type A[T] = C[T]
6+
[out]
7+
MypyFile:1(
8+
TypeAliasStmt:2(
9+
NameExpr(A)
10+
TypeParam(
11+
T)
12+
LambdaExpr:2(
13+
Block:-1(
14+
ReturnStmt:2(
15+
IndexExpr:2(
16+
NameExpr(C)
17+
NameExpr(T)))))))
18+
19+
[case testPEP695GenericFunction]
20+
# comment
21+
22+
def f[T](): pass
23+
def g[T: str](): pass
24+
def h[T: (int, str)](): pass
25+
[out]
26+
MypyFile:1(
27+
FuncDef:3(
28+
f
29+
TypeParam(
30+
T)
31+
Block:3(
32+
PassStmt:3()))
33+
FuncDef:4(
34+
g
35+
TypeParam(
36+
T
37+
str?)
38+
Block:4(
39+
PassStmt:4()))
40+
FuncDef:5(
41+
h
42+
TypeParam(
43+
T
44+
Values(
45+
int?
46+
str?))
47+
Block:5(
48+
PassStmt:5())))
49+
50+
[case testPEP695ParamSpec]
51+
# comment
52+
53+
def f[**P](): pass
54+
class C[T: int, **P]: pass
55+
[out]
56+
MypyFile:1(
57+
FuncDef:3(
58+
f
59+
TypeParam(
60+
**P)
61+
Block:3(
62+
PassStmt:3()))
63+
ClassDef:4(
64+
C
65+
TypeParam(
66+
T
67+
int?)
68+
TypeParam(
69+
**P)
70+
PassStmt:4()))
71+
72+
[case testPEP695TypeVarTuple]
73+
# comment
74+
75+
def f[*Ts](): pass
76+
class C[T: int, *Ts]: pass
77+
[out]
78+
MypyFile:1(
79+
FuncDef:3(
80+
f
81+
TypeParam(
82+
*Ts)
83+
Block:3(
84+
PassStmt:3()))
85+
ClassDef:4(
86+
C
87+
TypeParam(
88+
T
89+
int?)
90+
TypeParam(
91+
*Ts)
92+
PassStmt:4()))

0 commit comments

Comments
 (0)