Mailing List Archive

[3.9] bpo-42474: test TracebackException comparison to non-equal instances (GH-23557)
https://github.com/python/cpython/commit/586bdd1add2ca7236e3096ab7167862cf17f0939
commit: 586bdd1add2ca7236e3096ab7167862cf17f0939
branch: 3.9
author: Irit Katriel <iritkatriel@yahoo.com>
committer: gvanrossum <gvanrossum@gmail.com>
date: 2020-11-29T17:40:45-08:00
summary:

[3.9] bpo-42474: test TracebackException comparison to non-equal instances (GH-23557)

files:
M Lib/test/test_traceback.py

diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index f9a5f2fc53e1e..d564f3040ea18 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -1103,7 +1103,7 @@ def test_context(self):
self.assertEqual(exc_info[0], exc.exc_type)
self.assertEqual(str(exc_info[1]), str(exc))

- def test_comparison(self):
+ def test_comparison_basic(self):
try:
1/0
except Exception:
@@ -1115,6 +1115,43 @@ def test_comparison(self):
self.assertNotEqual(exc, object())
self.assertEqual(exc, ALWAYS_EQ)

+ 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):
@@ -1156,7 +1193,7 @@ def test_lookup_lines(self):
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")


_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins