diff options
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/support/__init__.py | 4 | ||||
| -rw-r--r-- | Lib/test/test_grammar.py | 12 |
2 files changed, 5 insertions, 11 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 22868d4..6c9e31a 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1061,8 +1061,8 @@ def make_bad_fd(): file.close() unlink(TESTFN) -def check_syntax_error(testcase, statement, *, lineno=None, offset=None): - with testcase.assertRaises(SyntaxError) as cm: +def check_syntax_error(testcase, statement, errtext='', *, lineno=None, offset=None): + with testcase.assertRaisesRegex(SyntaxError, errtext) as cm: compile(statement, '<test string>', 'exec') err = cm.exception testcase.assertIsNotNone(err.lineno) diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 88c22b8..d89bfdc 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -251,6 +251,8 @@ class CNS: class GrammarTests(unittest.TestCase): + check_syntax_error = check_syntax_error + # single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE # XXX can't test in a script -- this rule is only used when interactive @@ -920,15 +922,7 @@ class GrammarTests(unittest.TestCase): def g(): [x for x in [(yield 1)]] def g(): [x for x in [(yield from ())]] - def check(code, warntext): - with self.assertWarnsRegex(DeprecationWarning, warntext): - compile(code, '<test string>', 'exec') - import warnings - with warnings.catch_warnings(): - warnings.filterwarnings('error', category=DeprecationWarning) - with self.assertRaisesRegex(SyntaxError, warntext): - compile(code, '<test string>', 'exec') - + check = self.check_syntax_error check("def g(): [(yield x) for x in ()]", "'yield' inside list comprehension") check("def g(): [x for x in () if not (yield x)]", |
