diff options
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 3378ceb701..a25f3bf03a 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -156,6 +156,34 @@ class ExceptionTests(unittest.TestCase): ckmsg(s, "'continue' not properly in loop") ckmsg("continue\n", "'continue' not properly in loop") + def testSyntaxErrorMissingParens(self): + def ckmsg(src, msg, exception=SyntaxError): + try: + compile(src, '<fragment>', 'exec') + except exception as e: + if e.msg != msg: + self.fail("expected %s, got %s" % (msg, e.msg)) + else: + self.fail("failed to get expected SyntaxError") + + s = '''print "old style"''' + ckmsg(s, "Missing parentheses in call to 'print'. " + "Did you mean print(\"old style\")?") + + s = '''print "old style",''' + ckmsg(s, "Missing parentheses in call to 'print'. " + "Did you mean print(\"old style\", end=\" \")?") + + s = '''exec "old style"''' + ckmsg(s, "Missing parentheses in call to 'exec'") + + # should not apply to subclasses, see issue #31161 + s = '''if True:\nprint "No indent"''' + ckmsg(s, "expected an indented block", IndentationError) + + s = '''if True:\n print()\n\texec "mixed tabs and spaces"''' + ckmsg(s, "inconsistent use of tabs and spaces in indentation", TabError) + def testSyntaxErrorOffset(self): def check(src, lineno, offset): with self.assertRaises(SyntaxError) as cm: |