summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMartijn Pieters <github.com@zopatista.com>2017-08-22 20:11:09 (GMT)
committerƁukasz Langa <lukasz@langa.pl>2017-08-22 20:11:09 (GMT)
commit680f04a926bce04e4320ba883068c345eba502a6 (patch)
tree1230385653b1591d47c03bfce0d814fe321777a0 /Lib/test
parent468534d92f6879e925c4cd8a228ea300abfb7e4d (diff)
downloadcpython-680f04a926bce04e4320ba883068c345eba502a6.zip
cpython-680f04a926bce04e4320ba883068c345eba502a6.tar.gz
cpython-680f04a926bce04e4320ba883068c345eba502a6.tar.bz2
bpo-31161: only check for parens error for SyntaxError (#3083)
Subclasses such as IndentError and TabError should not have this message applied.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_exceptions.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 960fc0f..53851cb 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: