diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-20 02:29:54 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-20 02:29:54 (GMT) |
commit | ce1a9f309fd5b88e2792a8e31c237412fc163d28 (patch) | |
tree | 228d301b3e467c642333e1f4d85ac420084cfe3f /Lib/test/test_contextlib.py | |
parent | 5943ea76d529f9ea18c73a61e10c6f53bdcc864f (diff) | |
download | cpython-ce1a9f309fd5b88e2792a8e31c237412fc163d28.zip cpython-ce1a9f309fd5b88e2792a8e31c237412fc163d28.tar.gz cpython-ce1a9f309fd5b88e2792a8e31c237412fc163d28.tar.bz2 |
Added more tests for issue #27122.
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r-- | Lib/test/test_contextlib.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index a246c43..516403e 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -763,8 +763,9 @@ class TestExitStack(unittest.TestCase): self.assertIs(stack._exit_callbacks[-1], cm) def test_dont_reraise_RuntimeError(self): - """https://bugs.python.org/issue27122""" + # https://bugs.python.org/issue27122 class UniqueException(Exception): pass + class UniqueRuntimeError(RuntimeError): pass @contextmanager def second(): @@ -780,15 +781,20 @@ class TestExitStack(unittest.TestCase): except Exception as exc: raise exc - # The RuntimeError should be caught by second()'s exception + # The UniqueRuntimeError should be caught by second()'s exception # handler which chain raised a new UniqueException. with self.assertRaises(UniqueException) as err_ctx: with ExitStack() as es_ctx: es_ctx.enter_context(second()) es_ctx.enter_context(first()) - raise RuntimeError("please no infinite loop.") - - self.assertEqual(err_ctx.exception.args[0], "new exception") + raise UniqueRuntimeError("please no infinite loop.") + + exc = err_ctx.exception + self.assertIsInstance(exc, UniqueException) + self.assertIsInstance(exc.__context__, UniqueRuntimeError) + self.assertIsNone(exc.__context__.__context__) + self.assertIsNone(exc.__context__.__cause__) + self.assertIs(exc.__cause__, exc.__context__) class TestRedirectStream: |