mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
[3.12] gh-111366: Correctly show custom syntax error messages in the codeop module functions (GH-111384). (#111517)
This commit is contained in:
parent
7ac2c53333
commit
ca36426b1c
3 changed files with 31 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
|||
import unittest
|
||||
import warnings
|
||||
from test.support import warnings_helper
|
||||
from textwrap import dedent
|
||||
|
||||
from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
|
||||
|
||||
|
@ -308,6 +309,19 @@ class CodeopTests(unittest.TestCase):
|
|||
self.assertRegex(str(w[0].message), 'invalid escape sequence')
|
||||
self.assertEqual(w[0].filename, '<input>')
|
||||
|
||||
def assertSyntaxErrorMatches(self, code, message):
|
||||
with self.subTest(code):
|
||||
with self.assertRaisesRegex(SyntaxError, message):
|
||||
compile_command(code, symbol='exec')
|
||||
|
||||
def test_syntax_errors(self):
|
||||
self.assertSyntaxErrorMatches(
|
||||
dedent("""\
|
||||
def foo(x,x):
|
||||
pass
|
||||
"""), "duplicate argument 'x' in function definition")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue