|
4 | 4 | from io import StringIO
|
5 | 5 | import linecache
|
6 | 6 | import sys
|
| 7 | +import types |
7 | 8 | import inspect
|
8 | 9 | import unittest
|
9 | 10 | import re
|
@@ -1128,7 +1129,7 @@ def test_print_exception_bad_type_python(self):
|
1128 | 1129 | class BaseExceptionReportingTests:
|
1129 | 1130 |
|
1130 | 1131 | def get_exception(self, exception_or_callable):
|
1131 |
| - if isinstance(exception_or_callable, Exception): |
| 1132 | + if isinstance(exception_or_callable, BaseException): |
1132 | 1133 | return exception_or_callable
|
1133 | 1134 | try:
|
1134 | 1135 | exception_or_callable()
|
@@ -1850,6 +1851,31 @@ def exc():
|
1850 | 1851 | report = self.get_report(exc)
|
1851 | 1852 | self.assertEqual(report, expected)
|
1852 | 1853 |
|
| 1854 | + def test_KeyboardInterrupt_at_first_line_of_frame(self): |
| 1855 | + # see GH-93249 |
| 1856 | + def f(): |
| 1857 | + return sys._getframe() |
| 1858 | + |
| 1859 | + tb_next = None |
| 1860 | + frame = f() |
| 1861 | + lasti = 0 |
| 1862 | + lineno = f.__code__.co_firstlineno |
| 1863 | + tb = types.TracebackType(tb_next, frame, lasti, lineno) |
| 1864 | + |
| 1865 | + exc = KeyboardInterrupt() |
| 1866 | + exc.__traceback__ = tb |
| 1867 | + |
| 1868 | + expected = (f'Traceback (most recent call last):\n' |
| 1869 | + f' File "{__file__}", line {lineno}, in f\n' |
| 1870 | + f' def f():\n' |
| 1871 | + f'\n' |
| 1872 | + f'KeyboardInterrupt\n') |
| 1873 | + |
| 1874 | + report = self.get_report(exc) |
| 1875 | + # remove trailing writespace: |
| 1876 | + report = '\n'.join([l.rstrip() for l in report.split('\n')]) |
| 1877 | + self.assertEqual(report, expected) |
| 1878 | + |
1853 | 1879 |
|
1854 | 1880 | class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
|
1855 | 1881 | #
|
|
0 commit comments