8000 [3.9] bpo-42474: test TracebackException comparison to non-equal inst… · python/cpython@586bdd1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 586bdd1

Browse files
authored
[3.9] bpo-42474: test TracebackException comparison to non-equal instances (GH-23557)
1 parent a83119d commit 586bdd1

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

Lib/test/test_traceback.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ def test_context(self):
11031103
self.assertEqual(exc_info[0], exc.exc_type)
11041104
self.assertEqual(str(exc_info[1]), str(exc))
11051105

1106-
def test_comparison(self):
1106+
def test_comparison_basic(self):
11071107
try:
11081108
1/0
11091109
except Exception:
@@ -1115,6 +1115,43 @@ def test_comparison(self):
11151115
self.assertNotEqual(exc, object())
11161116
self.assertEqual(exc, ALWAYS_EQ)
11171117

1118+
def test_comparison_params_variations(self):
1119+
def raise_exc():
1120+
try:
1121+
raise ValueError('bad value')
1122+
except:
1123+
raise
1124+
1125+
def raise_with_locals():
1126+
x, y = 1, 2
1127+
raise_exc()
1128+
1129+
try:
1130+
raise_with_locals()
1131+
except Exception:
1132+
exc_info = sys.exc_info()
1133+
1134+
exc = traceback.TracebackException(*exc_info)
1135+
exc1 = traceback.TracebackException(*exc_info, limit=10)
1136+
exc2 = traceback.TracebackException(*exc_info, limit=2)
1137+
1138+
self.assertEqual(exc, exc1) # limit=10 gets all frames
1139+
self.assertNotEqual(exc, exc2) # limit=2 truncates the output
1140+
1141+
# locals change the output
1142+
exc3 = traceback.TracebackException(*exc_info, capture_locals=True)
1143+
self.assertNotEqual(exc, exc3)
1144+
1145+
# there are no locals in the innermost frame
1146+
exc4 = traceback.TracebackException(*exc_info, limit=-1)
1147+
exc5 = traceback.TracebackException(*exc_info, limit=-1, capture_locals=True)
1148+
self.assertEqual(exc4, exc5)
1149+
1150+
# there are locals in the next-to-innermost frame
1151+
exc6 = traceback.TracebackException(*exc_info, limit=-2)
1152+
exc7 = traceback.TracebackException(*exc_info, limit=-2, capture_locals=True)
1153+
self.assertNotEqual(exc6, exc7)
1154+
11181155
def test_unhashable(self):
11191156
class UnhashableException(Exception):
11201157
def __eq__(self, other):
@@ -1156,7 +1193,7 @@ def test_lookup_lines(self):
11561193
f = test_frame(c, None, None)
11571194
tb = test_tb(f, 6, None)
11581195
exc = traceback.TracebackException(Exception, e, tb, lookup_lines=False)
1159-
self.assertEqual({}, linecache.cache)
1196+
self.assertEqual(linecache.cache, {})
11601197
linecache.updatecache('/foo.py', globals())
11611198
self.assertEqual(exc.stack[0].line, "import sys")
11621199

0 commit comments

Comments
 (0)
0