diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-10-30 19:24:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-30 19:24:21 (GMT) |
commit | cd6e0a04a16535d8bc727c84f73730c53267184e (patch) | |
tree | f3df1c90e9cf0fd082ba478174fde12ebb107dc5 /Lib/test/test_codeop.py | |
parent | 624ace5a2f02715d084c29eaf2211cd0dd550690 (diff) | |
download | cpython-cd6e0a04a16535d8bc727c84f73730c53267184e.zip cpython-cd6e0a04a16535d8bc727c84f73730c53267184e.tar.gz cpython-cd6e0a04a16535d8bc727c84f73730c53267184e.tar.bz2 |
gh-111366: Correctly show custom syntax error messages in the codeop module functions (#111384)
Diffstat (limited to 'Lib/test/test_codeop.py')
-rw-r--r-- | Lib/test/test_codeop.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py index e3c3822..2abb6c6 100644 --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -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() |