diff options
author | Irit Katriel <iritkatriel@yahoo.com> | 2021-01-15 02:45:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-14 18:45:02 -0800 |
commit | 4c94d74152a511d977fe26a4f3a32b7352ba9024 (patch) | |
tree | cc0cb73d6512b874ae0886ee94aa0acce1c54488 /Lib/test | |
parent | bpo-42827: Fix crash on SyntaxError in multiline expressions (GH-24140) (diff) | |
download | cpython-4c94d74152a511d977fe26a4f3a32b7352ba9024.tar.gz cpython-4c94d74152a511d977fe26a4f3a32b7352ba9024.tar.bz2 cpython-4c94d74152a511d977fe26a4f3a32b7352ba9024.zip |
bpo-42877: add the 'compact' param to TracebackException's __init__ (#24179)
Use it to reduce the time and memory taken up by several of traceback's module-level functions.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_traceback.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 07555a0411a..33bdda02666 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -1173,6 +1173,46 @@ class TestTracebackException(unittest.TestCase): self.assertIn( "RecursionError: maximum recursion depth exceeded", res[-1]) + def test_compact_with_cause(self): + try: + try: + 1/0 + finally: + cause = Exception("cause") + raise Exception("uh oh") from cause + except Exception: + exc_info = sys.exc_info() + exc = traceback.TracebackException(*exc_info, compact=True) + expected_stack = traceback.StackSummary.extract( + traceback.walk_tb(exc_info[2])) + exc_cause = traceback.TracebackException(Exception, cause, None) + self.assertEqual(exc_cause, exc.__cause__) + self.assertEqual(None, exc.__context__) + self.assertEqual(True, exc.__suppress_context__) + self.assertEqual(expected_stack, exc.stack) + self.assertEqual(exc_info[0], exc.exc_type) + self.assertEqual(str(exc_info[1]), str(exc)) + + def test_compact_no_cause(self): + try: + try: + 1/0 + finally: + exc_info_context = sys.exc_info() + exc_context = traceback.TracebackException(*exc_info_context) + raise Exception("uh oh") + except Exception: + exc_info = sys.exc_info() + exc = traceback.TracebackException(*exc_info, compact=True) + expected_stack = traceback.StackSummary.extract( + traceback.walk_tb(exc_info[2])) + self.assertEqual(None, exc.__cause__) + self.assertEqual(exc_context, exc.__context__) + self.assertEqual(False, exc.__suppress_context__) + self.assertEqual(expected_stack, exc.stack) + self.assertEqual(exc_info[0], exc.exc_type) + self.assertEqual(str(exc_info[1]), str(exc)) + def test_no_refs_to_exception_and_traceback_objects(self): try: 1/0 |