]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111609: Test `end_offset` in SyntaxError subclass (#127830)
authorNice Zombies <nineteendo19d0@gmail.com>
Wed, 11 Dec 2024 18:32:54 +0000 (19:32 +0100)
committerGitHub <noreply@github.com>
Wed, 11 Dec 2024 18:32:54 +0000 (19:32 +0100)
Test `end_offset` in SyntaxError subclass

Lib/test/test_exceptions.py

index 5beeac3adfc06554fe1db43726932f716fa8252d..6ccfa9575f856908e9920cde8c17b77a419b3a94 100644 (file)
@@ -2274,6 +2274,21 @@ class SyntaxErrorTests(unittest.TestCase):
                     self.assertIn(expected, err.getvalue())
                     the_exception = exc
 
+    def test_subclass(self):
+        class MySyntaxError(SyntaxError):
+            pass
+
+        try:
+            raise MySyntaxError("bad bad", ("bad.py", 1, 2, "abcdefg", 1, 7))
+        except SyntaxError as exc:
+            with support.captured_stderr() as err:
+                sys.__excepthook__(*sys.exc_info())
+            self.assertIn("""
+  File "bad.py", line 1
+    abcdefg
+     ^^^^^
+""", err.getvalue())
+
     def test_encodings(self):
         self.addCleanup(unlink, TESTFN)
         source = (