cpython: ebc82b840163 (original) (raw)
Mercurial > cpython
changeset 102105:ebc82b840163
Added more tests for issue #27122. [#27122]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Mon, 20 Jun 2016 05:30:31 +0300 |
parents | 7b9ad68db14e(current diff)a14b93a4eb49(diff) |
children | 55ecc8fd88ac |
files | Lib/test/test_contextlib.py |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-)[+] [-] Lib/test/test_contextlib.py 14 |
line wrap: on
line diff
--- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -796,8 +796,9 @@ class TestExitStack(unittest.TestCase): self.assertIs(stack._exit_callbacks[-1], cm) def test_dont_reraise_RuntimeError(self):
"""https://bugs.python.org/issue27122"""[](#l1.7)
# https://bugs.python.org/issue27122[](#l1.8) class UniqueException(Exception): pass[](#l1.9)
class UniqueRuntimeError(RuntimeError): pass[](#l1.10)
@contextmanager def second(): @@ -813,15 +814,20 @@ class TestExitStack(unittest.TestCase): except Exception as exc: raise exc
# The RuntimeError should be caught by second()'s exception[](#l1.18)
# The UniqueRuntimeError should be caught by second()'s exception[](#l1.19) # handler which chain raised a new UniqueException.[](#l1.20) with self.assertRaises(UniqueException) as err_ctx:[](#l1.21) with ExitStack() as es_ctx:[](#l1.22) es_ctx.enter_context(second())[](#l1.23) es_ctx.enter_context(first())[](#l1.24)
raise RuntimeError("please no infinite loop.")[](#l1.25)
raise UniqueRuntimeError("please no infinite loop.")[](#l1.26)
self.assertEqual(err_ctx.exception.args[0], "new exception")[](#l1.28)
exc = err_ctx.exception[](#l1.29)
self.assertIsInstance(exc, UniqueException)[](#l1.30)
self.assertIsInstance(exc.__context__, UniqueRuntimeError)[](#l1.31)
self.assertIsNone(exc.__context__.__context__)[](#l1.32)
self.assertIsNone(exc.__context__.__cause__)[](#l1.33)
self.assertIs(exc.__cause__, exc.__context__)[](#l1.34)