Skip to content

Commit d1ed56e

Browse files
committed
Implement more tests (which may raise SyntaxError for us)
1 parent f4f5dea commit d1ed56e

File tree

2 files changed

+50
-35
lines changed

2 files changed

+50
-35
lines changed

tests/upstream_tests/match_test.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,29 @@
77
# this package
88
from formate_trailing_commas import trailing_commas_hook
99

10-
# TODO
11-
# @pytest.mark.parametrize(
12-
# 's',
13-
# (
14-
# pytest.param(
15-
# 'match x:\n'
16-
# ' case 1, 2:\n'
17-
# ' pass\n',
18-
# id='sequence without braces',
19-
# ),
20-
# pytest.param(
21-
# 'match x:\n'
22-
# ' case a():\n'
23-
# ' pass\n',
24-
# id='class without args',
25-
# ),
26-
# ),
27-
# )
28-
# def test_noop(s):
29-
# assert trailing_commas_hook(s, min_version=(2, 7)) == s
10+
@pytest.mark.parametrize(
11+
's',
12+
(
13+
pytest.param(
14+
'match x:\n'
15+
' case 1, 2:\n'
16+
' pass\n',
17+
id="sequence without braces",
18+
),
19+
pytest.param(
20+
'match x:\n'
21+
' case a():\n'
22+
' pass\n',
23+
id="class without args",
24+
),
25+
),
26+
)
27+
def test_noop_or_syntaxerror(s):
28+
if sys.version_info >= (3, 10):
29+
assert trailing_commas_hook(s, min_version=(2, 7)) == s
30+
else:
31+
with pytest.raises(SyntaxError, match="invalid syntax"):
32+
trailing_commas_hook(s, min_version=(2, 7))
3033

3134

3235
@pytest.mark.xfail(sys.version_info < (3, 10), reason="py310+")

tests/upstream_tests/with_test.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
@pytest.mark.parametrize(
1212
"src",
1313
(
14-
# TODO
15-
# 'from threading import Lock\n'
16-
# 'with (Lock() as l):\n'
17-
# ' pass',
18-
# id='simple named context manager',
19-
# ),
2014
pytest.param(
2115
'with (\n'
2216
' open("wat")\n'
@@ -32,21 +26,39 @@
3226
' open("/tmp/y.py") as g: pass',
3327
id="escaped newline",
3428
),
35-
# TODO
36-
# pytest.param(
37-
# 'with (open("/tmp/t.py") as f): pass',
38-
# id='single item',
39-
# ),
40-
# pytest.param(
41-
# 'with (open("/tmp/t.py") as t, open("/tmp/y.py") as y): pass',
42-
# id='single line',
43-
# ),
4429
),
4530
)
4631
def test_noop(src):
4732
assert trailing_commas_hook(src, min_version=(2, 7)) == src
4833

4934

35+
@pytest.mark.parametrize(
36+
"src",
37+
(
38+
pytest.param(
39+
'from threading import Lock\n'
40+
'with (Lock() as l):\n'
41+
' pass',
42+
id="simple named context manager",
43+
),
44+
pytest.param(
45+
'with (open("/tmp/t.py") as f): pass',
46+
id="single item",
47+
),
48+
pytest.param(
49+
'with (open("/tmp/t.py") as t, open("/tmp/y.py") as y): pass',
50+
id="single line",
51+
),
52+
),
53+
)
54+
def test_noop_or_syntaxerror(src):
55+
if sys.version_info >= (3, 9):
56+
assert trailing_commas_hook(src, min_version=(2, 7)) == src
57+
else:
58+
with pytest.raises(SyntaxError, match="invalid syntax"):
59+
trailing_commas_hook(src, min_version=(2, 7))
60+
61+
5062
@pytest.mark.xfail(sys.version_info < (3, 9), reason="py39+")
5163
@pytest.mark.parametrize(
5264
("src", "expected"),

0 commit comments

Comments
 (0)