[Python-checkins] cpython (merge 3.5 -> default): Added more tests for issue #27122.
serhiy.storchaka
python-checkins at python.org
Sun Jun 19 22:30:56 EDT 2016
https://hg.python.org/cpython/rev/ebc82b840163
changeset: 102105:ebc82b840163
parent: 102103:7b9ad68db14e
parent: 102104:a14b93a4eb49
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Jun 20 05:30:31 2016 +0300
summary:
Added more tests for issue #27122.
files:
Lib/test/test_contextlib.py | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -796,8 +796,9 @@
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():
@@ -813,15 +814,20 @@
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.")
+ raise UniqueRuntimeError("please no infinite loop.")
- self.assertEqual(err_ctx.exception.args[0], "new exception")
+ 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:
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list