573
573
self.assertIsInstance(inner_exc, ValueError)
574
574
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
576
def test_exit_exception_non_suppressing(self):
577
# http://bugs.python.org/issue19092
581
def suppress_exc(*exc_details):
585
with ExitStack() as stack:
586
stack.callback(lambda: None)
587
stack.callback(raise_exc, IndexError)
588
except Exception as exc:
589
self.assertIsInstance(exc, IndexError)
591
self.fail("Expected IndexError, but no exception was raised")
594
with ExitStack() as stack:
595
stack.callback(raise_exc, KeyError)
596
stack.push(suppress_exc)
597
stack.callback(raise_exc, IndexError)
598
except Exception as exc:
599
self.assertIsInstance(exc, KeyError)
601
self.fail("Expected KeyError, but no exception was raised")
603
def test_body_exception_suppress(self):
604
def suppress_exc(*exc_details):
607
with ExitStack() as stack:
608
stack.push(suppress_exc)
610
except IndexError as exc:
611
self.fail("Expected no exception, got IndexError")
576
613
def test_exit_exception_chaining_suppress(self):
577
614
with ExitStack() as stack:
578
615
stack.push(lambda *exc: True)