@@ -963,7 +963,9 @@ class CPythonTracebackLegacyErrorCaretTests(
963
963
Same set of tests as above but with Python's legacy internal traceback printing.
964
964
"""
965
965
966
- class TracebackFormatTests (unittest .TestCase ):
966
+
967
+ class TracebackFormatMixing :
968
+ DEBUG_RANGES = True
967
969
968
970
def some_exception (self ):
969
971
raise KeyError ('blah' )
@@ -1137,6 +1139,8 @@ def g(count=10):
1137
1139
)
1138
1140
expected = (tb_line + result_g ).splitlines ()
1139
1141
actual = stderr_g .getvalue ().splitlines ()
1142
+ if not self .DEBUG_RANGES :
1143
+ expected = [line for line in expected if not set (line .strip ()) == {"^" }]
1140
1144
self .assertEqual (actual , expected )
1141
1145
1142
1146
# Check 2 different repetitive sections
@@ -1173,6 +1177,8 @@ def h(count=10):
1173
1177
)
1174
1178
expected = (result_h + result_g ).splitlines ()
1175
1179
actual = stderr_h .getvalue ().splitlines ()
1180
+ if not self .DEBUG_RANGES :
1181
+ expected = [line for line in expected if not set (line .strip ()) == {"^" }]
1176
1182
self .assertEqual (actual , expected )
1177
1183
1178
1184
# Check the boundary conditions. First, test just below the cutoff.
@@ -1199,11 +1205,13 @@ def h(count=10):
1199
1205
)
1200
1206
tb_line = (
1201
1207
'Traceback (most recent call last):\n '
1202
- f' File "{ __file__ } ", line { lineno_g + 77 } , in _check_recursive_traceback_display\n '
1208
+ f' File "{ __file__ } ", line { lineno_g + 81 } , in _check_recursive_traceback_display\n '
1203
1209
' g(traceback._RECURSIVE_CUTOFF)\n '
1204
1210
)
1205
1211
expected = (tb_line + result_g ).splitlines ()
1206
1212
actual = stderr_g .getvalue ().splitlines ()
1213
+ if not self .DEBUG_RANGES :
1214
+ expected = [line for line in expected if not set (line .strip ()) == {"^" }]
1207
1215
self .assertEqual (actual , expected )
1208
1216
1209
1217
# Second, test just above the cutoff.
@@ -1231,24 +1239,24 @@ def h(count=10):
1231
1239
)
1232
1240
tb_line = (
1233
1241
'Traceback (most recent call last):\n '
1234
- f' File "{ __file__ } ", line { lineno_g + 108 } , in _check_recursive_traceback_display\n '
1242
+ f' File "{ __file__ } ", line { lineno_g + 114 } , in _check_recursive_traceback_display\n '
1235
1243
' g(traceback._RECURSIVE_CUTOFF + 1)\n '
1236
1244
)
1237
1245
expected = (tb_line + result_g ).splitlines ()
1238
1246
actual = stderr_g .getvalue ().splitlines ()
1247
+ if not self .DEBUG_RANGES :
1248
+ expected = [line for line in expected if not set (line .strip ()) == {"^" }]
1239
1249
self .assertEqual (actual , expected )
1240
1250
1241
1251
@requires_debug_ranges ()
1242
- def test_recursive_traceback_python (self ):
1243
- self ._check_recursive_traceback_display (traceback .print_exc )
1244
-
1245
- @cpython_only
1246
- @requires_debug_ranges ()
1247
- def test_recursive_traceback_cpython_internal (self ):
1248
- from _testcapi import exception_print
1249
- def render_exc ():
1250
- exception_print (sys .exception ())
1251
- self ._check_recursive_traceback_display (render_exc )
1252
+ def test_recursive_traceback (self ):
1253
+ if self .DEBUG_RANGES :
1254
+ self ._check_recursive_traceback_display (traceback .print_exc )
1255
+ else :
1256
+ from _testcapi import exception_print
1257
+ def render_exc ():
1258
+ exception_print (sys .exception ())
1259
+ self ._check_recursive_traceback_display (render_exc )
1252
1260
1253
1261
def test_format_stack (self ):
1254
1262
def fmt ():
@@ -1345,6 +1353,21 @@ def test_print_exception_bad_type_python(self):
1345
1353
boundaries = re .compile (
1346
1354
'(%s|%s)' % (re .escape (cause_message ), re .escape (context_message )))
1347
1355
1356
+ class TestTracebackFormat (unittest .TestCase , TracebackFormatMixing ):
1357
+ pass
1358
+
1359
+ @cpython_only
1360
+ class TestFallbackTracebackFormat (unittest .TestCase , TracebackFormatMixing ):
1361
+ DEBUG_RANGES = False
1362
+ def setUp (self ) -> None :
1363
+ self .original_hook = traceback ._print_exception_bltin
1364
+ traceback ._print_exception_bltin = lambda * args : 1 / 0
1365
+ return super ().setUp ()
1366
+
1367
+ def tearDown (self ) -> None :
1368
+ traceback ._print_exception_bltin = self .original_hook
1369
+ return super ().tearDown ()
1370
+
1348
1371
class BaseExceptionReportingTests :
1349
1372
1350
1373
def get_exception (self , exception_or_callable ):
0 commit comments