diff options
author | Irit Katriel <iritkatriel@yahoo.com> | 2020-11-30 01:41:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-30 01:41:19 (GMT) |
commit | d82e08d185d52086f4d921c08b853c76c80bebbe (patch) | |
tree | 5c1443a17519116a5c8f330c3a8d4cb3505eef33 /Lib/test | |
parent | b1c48e513624641d6472262c33d09624170ea1f5 (diff) | |
download | cpython-d82e08d185d52086f4d921c08b853c76c80bebbe.zip cpython-d82e08d185d52086f4d921c08b853c76c80bebbe.tar.gz cpython-d82e08d185d52086f4d921c08b853c76c80bebbe.tar.bz2 |
[3.8] bpo-42474: test TracebackException comparison to non-equal instances (GH-23558)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_traceback.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 96d85e2..8a80d58 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -1083,6 +1083,56 @@ class TestTracebackException(unittest.TestCase): self.assertEqual(exc_info[0], exc.exc_type) self.assertEqual(str(exc_info[1]), str(exc)) + def test_comparison_basic(self): + try: + 1/0 + except Exception: + exc_info = sys.exc_info() + exc = traceback.TracebackException(*exc_info) + exc2 = traceback.TracebackException(*exc_info) + self.assertIsNot(exc, exc2) + self.assertEqual(exc, exc2) + class MyObject: + pass + self.assertNotEqual(exc, MyObject()) + + def test_comparison_params_variations(self): + def raise_exc(): + try: + raise ValueError('bad value') + except: + raise + + def raise_with_locals(): + x, y = 1, 2 + raise_exc() + + try: + raise_with_locals() + except Exception: + exc_info = sys.exc_info() + + exc = traceback.TracebackException(*exc_info) + exc1 = traceback.TracebackException(*exc_info, limit=10) + exc2 = traceback.TracebackException(*exc_info, limit=2) + + self.assertEqual(exc, exc1) # limit=10 gets all frames + self.assertNotEqual(exc, exc2) # limit=2 truncates the output + + # locals change the output + exc3 = traceback.TracebackException(*exc_info, capture_locals=True) + self.assertNotEqual(exc, exc3) + + # there are no locals in the innermost frame + exc4 = traceback.TracebackException(*exc_info, limit=-1) + exc5 = traceback.TracebackException(*exc_info, limit=-1, capture_locals=True) + self.assertEqual(exc4, exc5) + + # there are locals in the next-to-innermost frame + exc6 = traceback.TracebackException(*exc_info, limit=-2) + exc7 = traceback.TracebackException(*exc_info, limit=-2, capture_locals=True) + self.assertNotEqual(exc6, exc7) + def test_unhashable(self): class UnhashableException(Exception): def __eq__(self, other): @@ -1124,7 +1174,7 @@ class TestTracebackException(unittest.TestCase): f = test_frame(c, None, None) tb = test_tb(f, 6, None) exc = traceback.TracebackException(Exception, e, tb, lookup_lines=False) - self.assertEqual({}, linecache.cache) + self.assertEqual(linecache.cache, {}) linecache.updatecache('/foo.py', globals()) self.assertEqual(exc.stack[0].line, "import sys") |