|
10 | 10 | from contextlib import * # Tests __all__
|
11 | 11 | from test import support
|
12 | 12 | from test.support import os_helper
|
| 13 | +from test.support.testcase import ExceptionIsLikeMixin |
13 | 14 | import weakref
|
14 | 15 |
|
15 | 16 |
|
@@ -1148,7 +1149,7 @@ class TestRedirectStderr(TestRedirectStream, unittest.TestCase):
|
1148 | 1149 | orig_stream = "stderr"
|
1149 | 1150 |
|
1150 | 1151 |
|
1151 |
| -class TestSuppress(unittest.TestCase): |
| 1152 | +class TestSuppress(ExceptionIsLikeMixin, unittest.TestCase): |
1152 | 1153 |
|
1153 | 1154 | @support.requires_docstrings
|
1154 | 1155 | def test_instance_docs(self):
|
@@ -1202,6 +1203,30 @@ def test_cm_is_reentrant(self):
|
1202 | 1203 | 1/0
|
1203 | 1204 | self.assertTrue(outer_continued)
|
1204 | 1205 |
|
| 1206 | + def test_exception_groups(self): |
| 1207 | + eg_ve = lambda: ExceptionGroup( |
| 1208 | + "EG with ValueErrors only", |
| 1209 | + [ValueError("ve1"), ValueError("ve2"), ValueError("ve3")], |
| 1210 | + ) |
| 1211 | + eg_all = lambda: ExceptionGroup( |
| 1212 | + "EG with many types of exceptions", |
| 1213 | + [ValueError("ve1"), KeyError("ke1"), ValueError("ve2"), KeyError("ke2")], |
| 1214 | + ) |
| 1215 | + with suppress(ValueError): |
| 1216 | + raise eg_ve() |
| 1217 | + with suppress(ValueError, KeyError): |
| 1218 | + raise eg_all() |
| 1219 | + with self.assertRaises(ExceptionGroup) as eg1: |
| 1220 | + with suppress(ValueError): |
| 1221 | + raise eg_all() |
| 1222 | + self.assertExceptionIsLike( |
| 1223 | + eg1.exception, |
| 1224 | + ExceptionGroup( |
| 1225 | + "EG with many types of exceptions", |
| 1226 | + [KeyError("ke1"), KeyError("ke2")], |
| 1227 | + ), |
| 1228 | + ) |
| 1229 | + |
1205 | 1230 |
|
1206 | 1231 | class TestChdir(unittest.TestCase):
|
1207 | 1232 | def make_relative_path(self, *parts):
|
|
0 commit comments