(self)
| 912 | 1/0 |
| 913 | |
| 914 | def test_exit_exception_traceback(self): |
| 915 | # This test captures the current behavior of ExitStack so that we know |
| 916 | # if we ever unintendedly change it. It is not a statement of what the |
| 917 | # desired behavior is (for instance, we may want to remove some of the |
| 918 | # internal contextlib frames). |
| 919 | |
| 920 | def raise_exc(exc): |
| 921 | raise exc |
| 922 | |
| 923 | try: |
| 924 | with self.exit_stack() as stack: |
| 925 | stack.callback(raise_exc, ValueError) |
| 926 | 1/0 |
| 927 | except ValueError as e: |
| 928 | exc = e |
| 929 | |
| 930 | self.assertIsInstance(exc, ValueError) |
| 931 | ve_frames = traceback.extract_tb(exc.__traceback__) |
| 932 | expected = \ |
| 933 | [('test_exit_exception_traceback', 'with self.exit_stack() as stack:')] + \ |
| 934 | self.callback_error_internal_frames + \ |
| 935 | [('_exit_wrapper', 'callback(*args, **kwds)'), |
| 936 | ('raise_exc', 'raise exc')] |
| 937 | |
| 938 | self.assertEqual( |
| 939 | [(f.name, f.line) for f in ve_frames], expected) |
| 940 | |
| 941 | self.assertIsInstance(exc.__context__, ZeroDivisionError) |
| 942 | zde_frames = traceback.extract_tb(exc.__context__.__traceback__) |
| 943 | self.assertEqual([(f.name, f.line) for f in zde_frames], |
| 944 | [('test_exit_exception_traceback', '1/0')]) |
| 945 | |
| 946 | def test_exit_exception_chaining_reference(self): |
| 947 | # Sanity check to make sure that ExitStack chaining matches |
nothing calls this directly
no test coverage detected