summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-10-01 23:24:56 +1000
committerNick Coghlan <ncoghlan@gmail.com>2013-10-01 23:24:56 +1000
commit2c516c873319c145afc898fa17a2315097c1c912 (patch)
tree9d9a9ed1fc94c1451cd0f10f12a2a67948cca5ca /Lib/test
parent5245ec30249e8f76f9bb8068357c5e4b405d5e8a (diff)
downloadcpython-2c516c873319c145afc898fa17a2315097c1c912.tar.gz
Close #19092: ExitStack now reraises exceptions from __exit__
Report and patch by Hrvoje Nik?i?
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_contextlib.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index e52ed91a58..9e45f70f85 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -573,6 +573,43 @@ class TestExitStack(unittest.TestCase):
self.assertIsInstance(inner_exc, ValueError)
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
+ def test_exit_exception_non_suppressing(self):
+ # http://bugs.python.org/issue19092
+ def raise_exc(exc):
+ raise exc
+
+ def suppress_exc(*exc_details):
+ return True
+
+ try:
+ with ExitStack() as stack:
+ stack.callback(lambda: None)
+ stack.callback(raise_exc, IndexError)
+ except Exception as exc:
+ self.assertIsInstance(exc, IndexError)
+ else:
+ self.fail("Expected IndexError, but no exception was raised")
+
+ try:
+ with ExitStack() as stack:
+ stack.callback(raise_exc, KeyError)
+ stack.push(suppress_exc)
+ stack.callback(raise_exc, IndexError)
+ except Exception as exc:
+ self.assertIsInstance(exc, KeyError)
+ else:
+ self.fail("Expected KeyError, but no exception was raised")
+
+ def test_body_exception_suppress(self):
+ def suppress_exc(*exc_details):
+ return True
+ try:
+ with ExitStack() as stack:
+ stack.push(suppress_exc)
+ 1/0
+ except IndexError as exc:
+ self.fail("Expected no exception, got IndexError")
+
def test_exit_exception_chaining_suppress(self):
with ExitStack() as stack:
stack.push(lambda *exc: True)