diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2013-10-01 13:28:00 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2013-10-01 13:28:00 (GMT) |
commit | e6f4631f0839a004c1d272c48811cdbed3e5ac9d (patch) | |
tree | 9cb22ea0168de7b6b812c5f1ce4c6e9fbd7360e4 /Lib/test/test_contextlib.py | |
parent | c13516b0a0fd3142b29e1f354c2080cd52948213 (diff) | |
parent | 1a33b2f35b9195b440b492afa87dcf83ba2ecca4 (diff) | |
download | cpython-e6f4631f0839a004c1d272c48811cdbed3e5ac9d.zip cpython-e6f4631f0839a004c1d272c48811cdbed3e5ac9d.tar.gz cpython-e6f4631f0839a004c1d272c48811cdbed3e5ac9d.tar.bz2 |
Merge #19092 from 3.3
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r-- | Lib/test/test_contextlib.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index a38cc48..2892917 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) |