aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorMatthieu Dartiailh <marul@laposte.net>2022-04-05 15:47:13 +0200
committerGitHub <noreply@github.com>2022-04-05 14:47:13 +0100
commitaa0f056a00c4bcaef83d729e042359ddae903382 (patch)
tree45b026af73776c5f38423e44b989df335f52f405 /Lib/test/test_exceptions.py
parentf1606a5ba50bdc4e7d335d62297b4b4043a25e6e (diff)
downloadcpython-aa0f056a00c4bcaef83d729e042359ddae903382.tar.gz
cpython-aa0f056a00c4bcaef83d729e042359ddae903382.zip
bpo-47212: Improve error messages for un-parenthesized generator expressions (GH-32302)
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index a75b7fae551..6dca79efef1 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -198,12 +198,17 @@ class ExceptionTests(unittest.TestCase):
s = '''if True:\n print()\n\texec "mixed tabs and spaces"'''
ckmsg(s, "inconsistent use of tabs and spaces in indentation", TabError)
- def check(self, src, lineno, offset, encoding='utf-8'):
+ def check(self, src, lineno, offset, end_lineno=None, end_offset=None, encoding='utf-8'):
with self.subTest(source=src, lineno=lineno, offset=offset):
with self.assertRaises(SyntaxError) as cm:
compile(src, '<fragment>', 'exec')
self.assertEqual(cm.exception.lineno, lineno)
self.assertEqual(cm.exception.offset, offset)
+ if end_lineno is not None:
+ self.assertEqual(cm.exception.end_lineno, end_lineno)
+ if end_offset is not None:
+ self.assertEqual(cm.exception.end_offset, end_offset)
+
if cm.exception.text is not None:
if not isinstance(src, str):
src = src.decode(encoding, 'replace')
@@ -235,6 +240,10 @@ class ExceptionTests(unittest.TestCase):
check('match ...:\n case {**rest, "key": value}:\n ...', 2, 19)
check("[a b c d e f]", 1, 2)
check("for x yfff:", 1, 7)
+ check("f(a for a in b, c)", 1, 3, 1, 15)
+ check("f(a for a in b if a, c)", 1, 3, 1, 20)
+ check("f(a, b for b in c)", 1, 6, 1, 18)
+ check("f(a, b for b in c, d)", 1, 6, 1, 18)
# Errors thrown by compile.c
check('class foo:return 1', 1, 11)