diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-10-27 03:19:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-27 03:19:34 (GMT) |
commit | 3d2f1f0b830d86f16f42c42b54d3ea4453dac318 (patch) | |
tree | 384f6a750bf7cb49a3f73b9fe7080d24e3208587 /Lib/test/test_string_literals.py | |
parent | a254120f2f1dd99fa64f12594d1ed19c67df7d64 (diff) | |
download | cpython-3d2f1f0b830d86f16f42c42b54d3ea4453dac318.zip cpython-3d2f1f0b830d86f16f42c42b54d3ea4453dac318.tar.gz cpython-3d2f1f0b830d86f16f42c42b54d3ea4453dac318.tar.bz2 |
gh-111380: Show SyntaxWarnings only once when parsing if invalid syntax is encouintered (#111381)
Diffstat (limited to 'Lib/test/test_string_literals.py')
-rw-r--r-- | Lib/test/test_string_literals.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_string_literals.py b/Lib/test/test_string_literals.py index 9b663c0..371e819 100644 --- a/Lib/test/test_string_literals.py +++ b/Lib/test/test_string_literals.py @@ -131,6 +131,18 @@ class TestLiterals(unittest.TestCase): self.assertEqual(exc.lineno, 1) self.assertEqual(exc.offset, 1) + # Check that the warning is raised ony once if there are syntax errors + + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always', category=SyntaxWarning) + with self.assertRaises(SyntaxError) as cm: + eval("'\\e' $") + exc = cm.exception + self.assertEqual(len(w), 1) + self.assertEqual(w[0].category, SyntaxWarning) + self.assertRegex(str(w[0].message), 'invalid escape sequence') + self.assertEqual(w[0].filename, '<string>') + def test_eval_str_invalid_octal_escape(self): for i in range(0o400, 0o1000): with self.assertWarns(SyntaxWarning): |