@@ -252,7 +252,7 @@ def do_test(firstlines, message, charset, lineno):
252
252
self .assertTrue (stdout [2 ].endswith (err_line ),
253
253
"Invalid traceback line: {0!r} instead of {1!r}" .format (
254
254
stdout [2 ], err_line ))
255
- actual_err_msg = stdout [3 if has_no_debug_ranges () else 4 ]
255
+ actual_err_msg = stdout [3 ]
256
256
self .assertTrue (actual_err_msg == err_msg ,
257
257
"Invalid error message: {0!r} instead of {1!r}" .format (
258
258
actual_err_msg , err_msg ))
@@ -704,23 +704,23 @@ class A: pass
704
704
)
705
705
self .assertEqual (result_lines , expected_error .splitlines ())
706
706
707
- # @cpython_only
708
- # @requires_debug_ranges()
709
- # class CPythonTracebackErrorCaretTests(TracebackErrorLocationCaretTests):
710
- # """
711
- # Same set of tests as above but with Python's internal traceback printing.
712
- # """
713
- # def get_exception(self, callable):
714
- # from _testcapi import exception_print
715
- # try:
716
- # callable()
717
- # self.fail("No exception thrown.")
718
- # except Exception as e:
719
- # with captured_output("stderr") as tbstderr:
720
- # exception_print(e)
721
- # return tbstderr.getvalue().splitlines()[:-1]
722
- #
723
- # callable_line = get_exception.__code__.co_firstlineno + 3
707
+ @cpython_only
708
+ @requires_debug_ranges ()
709
+ class CPythonTracebackErrorCaretTests (TracebackErrorLocationCaretTests ):
710
+ """
711
+ Same set of tests as above but with Python's internal traceback printing.
712
+ """
713
+ def get_exception (self , callable ):
714
+ from _testcapi import exception_print
715
+ try :
716
+ callable ()
717
+ self .fail ("No exception thrown." )
718
+ except Exception as e :
719
+ with captured_output ("stderr" ) as tbstderr :
720
+ exception_print (e )
721
+ return tbstderr .getvalue ().splitlines ()[:- 1 ]
722
+
723
+ callable_line = get_exception .__code__ .co_firstlineno + 3
724
724
725
725
726
726
class TracebackFormatTests (unittest .TestCase ):
@@ -1015,14 +1015,14 @@ def h(count=10):
1015
1015
def test_recursive_traceback_python (self ):
1016
1016
self ._check_recursive_traceback_display (traceback .print_exc )
1017
1017
1018
- # @cpython_only
1019
- # @requires_debug_ranges()
1020
- # def test_recursive_traceback_cpython_internal(self):
1021
- # from _testcapi import exception_print
1022
- # def render_exc():
1023
- # exc_type, exc_value, exc_tb = sys.exc_info()
1024
- # exception_print(exc_value)
1025
- # self._check_recursive_traceback_display(render_exc)
1018
+ @cpython_only
1019
+ @requires_debug_ranges ()
1020
+ def test_recursive_traceback_cpython_internal (self ):
1021
+ from _testcapi import exception_print
1022
+ def render_exc ():
1023
+ exc_type , exc_value , exc_tb = sys .exc_info ()
1024
+ exception_print (exc_value )
1025
+ self ._check_recursive_traceback_display (render_exc )
1026
1026
1027
1027
def test_format_stack (self ):
1028
1028
def fmt ():
@@ -1058,16 +1058,10 @@ def __eq__(self, other):
1058
1058
exception_print (exc_val )
1059
1059
1060
1060
tb = stderr_f .getvalue ().strip ().splitlines ()
1061
- if has_no_debug_ranges ():
1062
- self .assertEqual (11 , len (tb ))
1063
- self .assertEqual (context_message .strip (), tb [5 ])
1064
- self .assertIn ('UnhashableException: ex2' , tb [3 ])
1065
- self .assertIn ('UnhashableException: ex1' , tb [10 ])
1066
- else :
1067
- self .assertEqual (13 , len (tb ))
1068
- self .assertEqual (context_message .strip (), tb [6 ])
1069
- self .assertIn ('UnhashableException: ex2' , tb [4 ])
1070
- self .assertIn ('UnhashableException: ex1' , tb [12 ])
1061
+ self .assertEqual (11 , len (tb ))
1062
+ self .assertEqual (context_message .strip (), tb [5 ])
1063
+ self .assertIn ('UnhashableException: ex2' , tb [3 ])
1064
+ self .assertIn ('UnhashableException: ex1' , tb [10 ])
1071
1065
1072
1066
def deep_eg (self ):
1073
1067
e = TypeError (1 )
@@ -1451,15 +1445,17 @@ def __str__(self):
1451
1445
# #### Exception Groups ####
1452
1446
1453
1447
def test_exception_group_basic (self ):
1448
+ self .maxDiff = None
1454
1449
def exc ():
1455
- raise ExceptionGroup ("eg" , [ValueError (1 ), TypeError (2 )])
1450
+ if True : raise ExceptionGroup ("eg" , [ValueError (1 ), TypeError (2 )])
1456
1451
1457
1452
expected = (
1458
1453
f' + Exception Group Traceback (most recent call last):\n '
1459
1454
f' | File "{ __file__ } ", line { self .callable_line } , in get_exception\n '
1460
1455
f' | exception_or_callable()\n '
1461
1456
f' | File "{ __file__ } ", line { exc .__code__ .co_firstlineno + 1 } , in exc\n '
1462
- f' | raise ExceptionGroup("eg", [ValueError(1), TypeError(2)])\n '
1457
+ f' | if True: raise ExceptionGroup("eg", [ValueError(1), TypeError(2)])\n '
1458
+ f' | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n '
1463
1459
f' | ExceptionGroup: eg (2 sub-exceptions)\n '
1464
1460
f' +-+---------------- 1 ----------------\n '
1465
1461
f' | ValueError: 1\n '
@@ -1474,13 +1470,14 @@ def test_exception_group_cause(self):
1474
1470
def exc ():
1475
1471
EG = ExceptionGroup
1476
1472
try :
1477
- raise EG ("eg1" , [ValueError (1 ), TypeError (2 )])
1473
+ if True : raise EG ("eg1" , [ValueError (1 ), TypeError (2 )])
1478
1474
except Exception as e :
1479
1475
raise EG ("eg2" , [ValueError (3 ), TypeError (4 )]) from e
1480
1476
1481
1477
expected = (f' + Exception Group Traceback (most recent call last):\n '
1482
1478
f' | File "{ __file__ } ", line { exc .__code__ .co_firstlineno + 3 } , in exc\n '
1483
- f' | raise EG("eg1", [ValueError(1), TypeError(2)])\n '
1479
+ f' | if True: raise EG("eg1", [ValueError(1), TypeError(2)])\n '
1480
+ f' | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n '
1484
1481
f' | ExceptionGroup: eg1 (2 sub-exceptions)\n '
1485
1482
f' +-+---------------- 1 ----------------\n '
1486
1483
f' | ValueError: 1\n '
@@ -1510,7 +1507,7 @@ def exc():
1510
1507
EG = ExceptionGroup
1511
1508
try :
1512
1509
try :
1513
- raise EG ("eg1" , [ValueError (1 ), TypeError (2 )])
1510
+ if True : raise EG ("eg1" , [ValueError (1 ), TypeError (2 )])
1514
1511
except :
1515
1512
raise EG ("eg2" , [ValueError (3 ), TypeError (4 )])
1516
1513
except :
@@ -1519,7 +1516,8 @@ def exc():
1519
1516
expected = (
1520
1517
f' + Exception Group Traceback (most recent call last):\n '
1521
1518
f' | File "{ __file__ } ", line { exc .__code__ .co_firstlineno + 4 } , in exc\n '
1522
- f' | raise EG("eg1", [ValueError(1), TypeError(2)])\n '
1519
+ f' | if True: raise EG("eg1", [ValueError(1), TypeError(2)])\n '
1520
+ f' | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n '
1523
1521
f' | ExceptionGroup: eg1 (2 sub-exceptions)\n '
1524
1522
f' +-+---------------- 1 ----------------\n '
1525
1523
f' | ValueError: 1\n '
@@ -1558,7 +1556,7 @@ def exc():
1558
1556
TE = TypeError
1559
1557
try :
1560
1558
try :
1561
- raise EG ("nested" , [TE (2 ), TE (3 )])
1559
+ if True : raise EG ("nested" , [TE (2 ), TE (3 )])
1562
1560
except Exception as e :
1563
1561
exc = e
1564
1562
raise EG ("eg" , [VE (1 ), exc , VE (4 )])
@@ -1574,7 +1572,8 @@ def exc():
1574
1572
f' +---------------- 2 ----------------\n '
1575
1573
f' | Exception Group Traceback (most recent call last):\n '
1576
1574
f' | File "{ __file__ } ", line { exc .__code__ .co_firstlineno + 6 } , in exc\n '
1577
- f' | raise EG("nested", [TE(2), TE(3)])\n '
1575
+ f' | if True: raise EG("nested", [TE(2), TE(3)])\n '
1576
+ f' | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n '
1578
1577
f' | ExceptionGroup: nested (2 sub-exceptions)\n '
1579
1578
f' +-+---------------- 1 ----------------\n '
1580
1579
f' | TypeError: 2\n '
@@ -1732,7 +1731,7 @@ def exc():
1732
1731
excs = []
1733
1732
for msg in ['bad value' , 'terrible value' ]:
1734
1733
try :
1735
- raise ValueError (msg )
1734
+ if True : raise ValueError (msg )
1736
1735
except ValueError as e :
1737
1736
e .add_note (f'the { msg } ' )
1738
1737
excs .append (e )
@@ -1761,13 +1760,15 @@ def exc():
1761
1760
f' +-+---------------- 1 ----------------\n '
1762
1761
f' | Traceback (most recent call last):\n '
1763
1762
f' | File "{ __file__ } ", line { exc .__code__ .co_firstlineno + 5 } , in exc\n '
1764
- f' | raise ValueError(msg)\n '
1763
+ f' | if True: raise ValueError(msg)\n '
1764
+ f' | ^^^^^^^^^^^^^^^^^^^^^\n '
1765
1765
f' | ValueError: bad value\n '
1766
1766
f' | the bad value\n '
1767
1767
f' +---------------- 2 ----------------\n '
1768
1768
f' | Traceback (most recent call last):\n '
1769
1769
f' | File "{ __file__ } ", line { exc .__code__ .co_firstlineno + 5 } , in exc\n '
1770
- f' | raise ValueError(msg)\n '
1770
+ f' | if True: raise ValueError(msg)\n '
1771
+ f' | ^^^^^^^^^^^^^^^^^^^^^\n '
1771
1772
f' | ValueError: terrible value\n '
1772
1773
f' | the terrible value\n '
1773
1774
f' +------------------------------------\n ' )
@@ -1781,7 +1782,7 @@ def exc():
1781
1782
excs = []
1782
1783
for msg in ['bad value' , 'terrible value' ]:
1783
1784
try :
1784
- raise ValueError (msg )
1785
+ if True : raise ValueError (msg )
1785
1786
except ValueError as e :
1786
1787
e .add_note (f'the { msg } ' )
1787
1788
e .add_note (f'Goodbye { msg } ' )
@@ -1813,14 +1814,16 @@ def exc():
1813
1814
f' +-+---------------- 1 ----------------\n '
1814
1815
f' | Traceback (most recent call last):\n '
1815
1816
f' | File "{ __file__ } ", line { exc .__code__ .co_firstlineno + 5 } , in exc\n '
1816
- f' | raise ValueError(msg)\n '
1817
+ f' | if True: raise ValueError(msg)\n '
1818
+ f' | ^^^^^^^^^^^^^^^^^^^^^\n '
1817
1819
f' | ValueError: bad value\n '
1818
1820
f' | the bad value\n '
1819
1821
f' | Goodbye bad value\n '
1820
1822
f' +---------------- 2 ----------------\n '
1821
1823
f' | Traceback (most recent call last):\n '
1822
1824
f' | File "{ __file__ } ", line { exc .__code__ .co_firstlineno + 5 } , in exc\n '
1823
- f' | raise ValueError(msg)\n '
1825
+ f' | if True: raise ValueError(msg)\n '
1826
+ f' | ^^^^^^^^^^^^^^^^^^^^^\n '
1824
1827
f' | ValueError: terrible value\n '
1825
1828
f' | the terrible value\n '
1826
1829
f' | Goodbye terrible value\n '
@@ -1871,18 +1874,18 @@ def get_report(self, e):
1871
1874
return s
1872
1875
1873
1876
1874
- # class CExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
1875
- # #
1876
- # # This checks built-in reporting by the interpreter.
1877
- # #
1878
- #
1879
- # @cpython_only
1880
- # def get_report(self, e):
1881
- # from _testcapi import exception_print
1882
- # e = self.get_exception(e)
1883
- # with captured_output("stderr") as s:
1884
- # exception_print(e)
1885
- # return s.getvalue()
1877
+ class CExcReportingTests (BaseExceptionReportingTests , unittest .TestCase ):
1878
+ #
1879
+ # This checks built-in reporting by the interpreter.
1880
+ #
1881
+
1882
+ @cpython_only
1883
+ def get_report (self , e ):
1884
+ from _testcapi import exception_print
1885
+ e = self .get_exception (e )
1886
+ with captured_output ("stderr" ) as s :
1887
+ exception_print (e )
1888
+ return s .getvalue ()
1886
1889
1887
1890
1888
1891
class LimitTests (unittest .TestCase ):
0 commit comments