summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_contextlib.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2006-04-24 04:37:15 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2006-04-24 04:37:15 (GMT)
commitda2268feecd4b956161ed7fdd05da125606189cc (patch)
tree0e387c87ccb58228c8030ad7951db225e0a13ec1 /Lib/test/test_contextlib.py
parent27ec1a773c92b6a9a144a45334ce2b38ae6118b6 (diff)
downloadcpython-da2268feecd4b956161ed7fdd05da125606189cc.zip
cpython-da2268feecd4b956161ed7fdd05da125606189cc.tar.gz
cpython-da2268feecd4b956161ed7fdd05da125606189cc.tar.bz2
Fix contextlib.nested to cope with exit methods raising and handling exceptions
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r--Lib/test/test_contextlib.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 97470c7..c23e428 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -146,6 +146,29 @@ class NestedTestCase(unittest.TestCase):
else:
self.fail("Didn't raise ZeroDivisionError")
+ def test_nested_right_exception(self):
+ state = []
+ @contextmanager
+ def a():
+ yield 1
+ class b(object):
+ def __enter__(self):
+ return 2
+ def __exit__(self, *exc_info):
+ try:
+ raise Exception()
+ except:
+ pass
+ try:
+ with nested(a(), b()) as (x, y):
+ 1/0
+ except ZeroDivisionError:
+ self.assertEqual((x, y), (1, 2))
+ except Exception:
+ self.fail("Reraised wrong exception")
+ else:
+ self.fail("Didn't raise ZeroDivisionError")
+
def test_nested_b_swallows(self):
@contextmanager
def a():