MCPcopy Index your code
hub / github.com/python/cpython / test_exit_exception_traceback

Method test_exit_exception_traceback

Lib/test/test_contextlib.py:914–944  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

assertIsInstanceMethod · 0.80
callbackMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected