summaryrefslogtreecommitdiff
path: root/Lib/test/test_contextlib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-06-20 05:30:31 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-06-20 05:30:31 +0300
commit9a573a0c23f4814946393a901b3f0ecbf91c268b (patch)
tree4830571c882ab5071f426fc754d4ec4583630560 /Lib/test/test_contextlib.py
parentb84f029baa20608fc1598857ad45774af7064b90 (diff)
parentce1a9f309fd5b88e2792a8e31c237412fc163d28 (diff)
downloadcpython-git-9a573a0c23f4814946393a901b3f0ecbf91c268b.tar.gz
Added more tests for issue #27122.
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r--Lib/test/test_contextlib.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 2c6e0e798f..c04c804af5 100644
--- 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"""
+ # https://bugs.python.org/issue27122
class UniqueException(Exception): pass
+ class UniqueRuntimeError(RuntimeError): pass
@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
+ # 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: