| 736 | self.assertEqual(result, []) |
| 737 | |
| 738 | def test_push(self): |
| 739 | exc_raised = ZeroDivisionError |
| 740 | def _expect_exc(exc_type, exc, exc_tb): |
| 741 | self.assertIs(exc_type, exc_raised) |
| 742 | def _suppress_exc(*exc_details): |
| 743 | return True |
| 744 | def _expect_ok(exc_type, exc, exc_tb): |
| 745 | self.assertIsNone(exc_type) |
| 746 | self.assertIsNone(exc) |
| 747 | self.assertIsNone(exc_tb) |
| 748 | class ExitCM(object): |
| 749 | def __init__(self, check_exc): |
| 750 | self.check_exc = check_exc |
| 751 | def __enter__(self): |
| 752 | self.fail("Should not be called!") |
| 753 | def __exit__(self, *exc_details): |
| 754 | self.check_exc(*exc_details) |
| 755 | with self.exit_stack() as stack: |
| 756 | stack.push(_expect_ok) |
| 757 | self.assertIs(stack._exit_callbacks[-1][1], _expect_ok) |
| 758 | cm = ExitCM(_expect_ok) |
| 759 | stack.push(cm) |
| 760 | self.assertIs(stack._exit_callbacks[-1][1].__self__, cm) |
| 761 | stack.push(_suppress_exc) |
| 762 | self.assertIs(stack._exit_callbacks[-1][1], _suppress_exc) |
| 763 | cm = ExitCM(_expect_exc) |
| 764 | stack.push(cm) |
| 765 | self.assertIs(stack._exit_callbacks[-1][1].__self__, cm) |
| 766 | stack.push(_expect_exc) |
| 767 | self.assertIs(stack._exit_callbacks[-1][1], _expect_exc) |
| 768 | stack.push(_expect_exc) |
| 769 | self.assertIs(stack._exit_callbacks[-1][1], _expect_exc) |
| 770 | 1/0 |
| 771 | |
| 772 | def test_enter_context(self): |
| 773 | class TestCM(object): |