summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_except_star.py
diff options
context:
space:
mode:
authorƁukasz Langa <lukasz@langa.pl>2023-04-24 22:17:02 (GMT)
committerGitHub <noreply@github.com>2023-04-24 22:17:02 (GMT)
commit22bed58e531ce780d91f3364c5ace98fad28c2e8 (patch)
tree09719c749f02573ed8f47cb5f682651596f008e8 /Lib/test/test_except_star.py
parent19e4f757de8c7cf2b4b9b4cbb32e376d0e50d2d4 (diff)
downloadcpython-22bed58e531ce780d91f3364c5ace98fad28c2e8.zip
cpython-22bed58e531ce780d91f3364c5ace98fad28c2e8.tar.gz
cpython-22bed58e531ce780d91f3364c5ace98fad28c2e8.tar.bz2
gh-103791: Make contextlib.suppress also act on exceptions within an ExceptionGroup (#103792)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_except_star.py')
-rw-r--r--Lib/test/test_except_star.py22
1 files changed, 2 insertions, 20 deletions
diff --git a/Lib/test/test_except_star.py b/Lib/test/test_except_star.py
index c5167c5..bc66f90 100644
--- a/Lib/test/test_except_star.py
+++ b/Lib/test/test_except_star.py
@@ -1,6 +1,7 @@
import sys
import unittest
import textwrap
+from test.support.testcase import ExceptionIsLikeMixin
class TestInvalidExceptStar(unittest.TestCase):
def test_mixed_except_and_except_star_is_syntax_error(self):
@@ -169,26 +170,7 @@ class TestBreakContinueReturnInExceptStarBlock(unittest.TestCase):
self.assertIsInstance(exc, ExceptionGroup)
-class ExceptStarTest(unittest.TestCase):
- def assertExceptionIsLike(self, exc, template):
- if exc is None and template is None:
- return
-
- if template is None:
- self.fail(f"unexpected exception: {exc}")
-
- if exc is None:
- self.fail(f"expected an exception like {template!r}, got None")
-
- if not isinstance(exc, ExceptionGroup):
- self.assertEqual(exc.__class__, template.__class__)
- self.assertEqual(exc.args[0], template.args[0])
- else:
- self.assertEqual(exc.message, template.message)
- self.assertEqual(len(exc.exceptions), len(template.exceptions))
- for e, t in zip(exc.exceptions, template.exceptions):
- self.assertExceptionIsLike(e, t)
-
+class ExceptStarTest(ExceptionIsLikeMixin, unittest.TestCase):
def assertMetadataEqual(self, e1, e2):
if e1 is None or e2 is None:
self.assertTrue(e1 is None and e2 is None)