Skip to content

Commit e0b46ea

Browse files
committed
Additional tests
1 parent 66e3bec commit e0b46ea

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

Lib/test/test_syntax.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,14 +2225,24 @@
22252225
Traceback (most recent call last):
22262226
SyntaxError: Expected one or more names after 'import'
22272227
2228+
# Missing comma between import clauses
2229+
22282230
>>> import a b
22292231
Traceback (most recent call last):
22302232
SyntaxError: expected comma between import clauses
22312233
2234+
>>> import a, b c
2235+
Traceback (most recent call last):
2236+
SyntaxError: expected comma between import clauses
2237+
22322238
>>> import a.a as a b.b
22332239
Traceback (most recent call last):
22342240
SyntaxError: expected comma between import clauses
22352241
2242+
>>> import a.a as a b.b as b
2243+
Traceback (most recent call last):
2244+
SyntaxError: expected comma between import clauses
2245+
22362246
>>> from x import a b
22372247
Traceback (most recent call last):
22382248
SyntaxError: expected comma between import clauses
@@ -2241,6 +2251,22 @@
22412251
Traceback (most recent call last):
22422252
SyntaxError: expected comma between import clauses
22432253
2254+
>>> from x import (a
2255+
... b)
2256+
Traceback (most recent call last):
2257+
SyntaxError: expected comma between import clauses
2258+
2259+
>>> from x import (a as a
2260+
... b)
2261+
Traceback (most recent call last):
2262+
SyntaxError: expected comma between import clauses
2263+
2264+
>>> from x import (a,
2265+
... b as b
2266+
... c)
2267+
Traceback (most recent call last):
2268+
SyntaxError: expected comma between import clauses
2269+
22442270
>>> (): int
22452271
Traceback (most recent call last):
22462272
SyntaxError: only single target (not tuple) can be annotated
@@ -3521,6 +3547,40 @@ def test_ifexp_body_stmt_else_stmt(self):
35213547
]:
35223548
self._check_error(f"x = {lhs_stmt} if 1 else {rhs_stmt}", msg)
35233549

3550+
def test_import_missing_comma(self):
3551+
self._check_error("import a.a b.b",
3552+
"expected comma between import clauses",
3553+
offset=8, end_offset=8 + len("a.a b.b"))
3554+
self._check_error(
3555+
"""if 1:
3556+
from x import (
3557+
a,
3558+
b
3559+
c,
3560+
)
3561+
""",
3562+
errtext="expected comma between import clauses",
3563+
lineno=4,
3564+
end_lineno=5,
3565+
offset=17,
3566+
end_offset=18,
3567+
)
3568+
self._check_error(
3569+
"""if 1:
3570+
from x import (
3571+
a,
3572+
b as b
3573+
c as c,
3574+
)
3575+
""",
3576+
errtext="expected comma between import clauses",
3577+
lineno=4,
3578+
end_lineno=5,
3579+
offset=22,
3580+
end_offset=18,
3581+
)
3582+
3583+
35243584

35253585
class LazyImportRestrictionTestCase(SyntaxErrorTestCase):
35263586
"""Test syntax restrictions for lazy imports."""

0 commit comments

Comments
 (0)