diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2014-06-16 09:49:12 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2014-06-16 09:49:12 (GMT) |
commit | 26171993fe629c614e62c7aef1196c0f53a30d85 (patch) | |
tree | 9222424eee6d492c4a68a6a6f2b1163b5b6f14b1 /Lib/test/test_grammar.py | |
parent | 69e3dbcb86c46408572b1541f7fa879b971c9d5f (diff) | |
parent | 5b1fdc1e377df88078f7788bf85dfebd353dc178 (diff) | |
download | cpython-26171993fe629c614e62c7aef1196c0f53a30d85.zip cpython-26171993fe629c614e62c7aef1196c0f53a30d85.tar.gz cpython-26171993fe629c614e62c7aef1196c0f53a30d85.tar.bz2 |
Merge issue #21669 from 3.4
Diffstat (limited to 'Lib/test/test_grammar.py')
-rw-r--r-- | Lib/test/test_grammar.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index b363f99..7069fb9 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -390,6 +390,31 @@ class GrammarTests(unittest.TestCase): check_syntax_error(self, "x + 1 = 1") check_syntax_error(self, "a + 1 = b + 2") + # Check the heuristic for print & exec covers significant cases + # As well as placing some limits on false positives + def test_former_statements_refer_to_builtins(self): + keywords = "print", "exec" + # Cases where we want the custom error + cases = [ + "{} foo", + "{} {{1:foo}}", + "if 1: {} foo", + "if 1: {} {{1:foo}}", + "if 1:\n {} foo", + "if 1:\n {} {{1:foo}}", + ] + for keyword in keywords: + custom_msg = "call to '{}'".format(keyword) + for case in cases: + source = case.format(keyword) + with self.subTest(source=source): + with self.assertRaisesRegex(SyntaxError, custom_msg): + exec(source) + source = source.replace("foo", "(foo.)") + with self.subTest(source=source): + with self.assertRaisesRegex(SyntaxError, "invalid syntax"): + exec(source) + def test_del_stmt(self): # 'del' exprlist abc = [1,2,3] |