mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Merge issue #21669 from 3.4
This commit is contained in:
commit
26171993fe
3 changed files with 165 additions and 0 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue