Skip to content

Commit 8540ee6

Browse files
committed
Fix traceback, syntax errors, and exception handling
1 parent 6c9314a commit 8540ee6

22 files changed

+356
-164
lines changed

Lib/test/test_cmd_line_script.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,6 @@ def test_dash_m_main_traceback(self):
548548
self.assertIn(b'Exception in __main__ module', err)
549549
self.assertIn(b'Traceback', err)
550550

551-
# TODO: RUSTPYTHON
552-
@unittest.expectedFailure
553551
def test_pep_409_verbiage(self):
554552
# Make sure PEP 409 syntax properly suppresses
555553
# the context of an exception

Lib/test/test_code_module.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def test_console_stderr(self):
9191
else:
9292
raise AssertionError("no console stdout")
9393

94-
@unittest.expectedFailure # TODO: RUSTPYTHON; + 'SyntaxError: invalid syntax']
9594
def test_syntax_error(self):
9695
self.infunc.side_effect = ["def f():",
9796
" x = ?",
@@ -166,7 +165,6 @@ def test_sysexcepthook(self):
166165
' File "<console>", line 2, in f\n',
167166
'ValueError: BOOM!\n'])
168167

169-
@unittest.expectedFailure # TODO: RUSTPYTHON; + 'SyntaxError: invalid syntax\n']
170168
def test_sysexcepthook_syntax_error(self):
171169
self.infunc.side_effect = ["def f():",
172170
" x = ?",
@@ -285,7 +283,6 @@ def test_exit_msg(self):
285283
self.assertEqual(err_msg, ['write', (expected,), {}])
286284

287285

288-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: '\nAttributeError\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File "<console>", line 1, in <module>\nValueError\n' not found in 'Python <MagicMock name=\'sys.version\' id=\'94615517503920\'> on <MagicMock name=\'sys.platform\' id=\'94615517656384\'>\nType "help", "copyright", "credits" or "license" for more information.\n(InteractiveConsole)\nAttributeError\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File "<console>", line 1, in <module>\nValueError: \n\nnow exiting InteractiveConsole...\n'
289286
def test_cause_tb(self):
290287
self.infunc.side_effect = ["raise ValueError('') from AttributeError",
291288
EOFError('Finished')]

Lib/test/test_contextlib.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,6 @@ def __exit__(self, *exc_details):
924924
self.assertIsInstance(inner_exc, ValueError)
925925
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
926926

927-
# TODO: RUSTPYTHON
928-
@unittest.expectedFailure
929927
def test_exit_exception_chaining(self):
930928
# Ensure exception chaining matches the reference behaviour
931929
def raise_exc(exc):
@@ -957,8 +955,6 @@ def suppress_exc(*exc_details):
957955
self.assertIsInstance(inner_exc, ValueError)
958956
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
959957

960-
# TODO: RUSTPYTHON
961-
@unittest.expectedFailure
962958
def test_exit_exception_explicit_none_context(self):
963959
# Ensure ExitStack chaining matches actual nested `with` statements
964960
# regarding explicit __context__ = None.
@@ -1053,8 +1049,6 @@ def gets_the_context_right(exc):
10531049
self.assertIsNone(
10541050
exc.__context__.__context__.__context__.__context__)
10551051

1056-
# TODO: RUSTPYTHON
1057-
@unittest.expectedFailure
10581052
def test_exit_exception_with_existing_context(self):
10591053
# Addresses a lack of test coverage discovered after checking in a
10601054
# fix for issue 20317 that still contained debugging code.

Lib/test/test_contextlib_async.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,6 @@ async def __aenter__(self):
650650
await stack.enter_async_context(LacksExit())
651651
self.assertFalse(stack._exit_callbacks)
652652

653-
@unittest.expectedFailure # TODO: RUSTPYTHON
654653
async def test_async_exit_exception_chaining(self):
655654
# Ensure exception chaining matches the reference behaviour
656655
async def raise_exc(exc):
@@ -682,7 +681,6 @@ async def suppress_exc(*exc_details):
682681
self.assertIsInstance(inner_exc, ValueError)
683682
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
684683

685-
@unittest.expectedFailure # TODO: RUSTPYTHON
686684
async def test_async_exit_exception_explicit_none_context(self):
687685
# Ensure AsyncExitStack chaining matches actual nested `with` statements
688686
# regarding explicit __context__ = None.

Lib/test/test_exceptions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,6 @@ def __del__(self):
17451745
f"deallocator {obj_repr}")
17461746
self.assertIsNotNone(cm.unraisable.exc_traceback)
17471747

1748-
@unittest.expectedFailure # TODO: RUSTPYTHON
17491748
def test_unhandled(self):
17501749
# Check for sensible reporting of unhandled exceptions
17511750
for exc_type in (ValueError, BrokenStrException):
@@ -2283,7 +2282,6 @@ def test_multiline_not_highlighted(self):
22832282
class SyntaxErrorTests(unittest.TestCase):
22842283
maxDiff = None
22852284

2286-
@unittest.expectedFailure # TODO: RUSTPYTHON
22872285
@force_not_colorized
22882286
def test_range_of_offsets(self):
22892287
cases = [

Lib/test/test_grammar.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ def test_ellipsis(self):
221221
self.assertTrue(x is Ellipsis)
222222
self.assertRaises(SyntaxError, eval, ".. .")
223223

224-
@unittest.expectedFailure # TODO: RUSTPYTHON
225224
def test_eof_error(self):
226225
samples = ("def foo(", "\ndef foo(", "def foo(\n")
227226
for s in samples:

Lib/test/test_inspect/test_inspect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,6 @@ def test_stack(self):
568568
self.assertIn('inspect.stack()', record.code_context[0])
569569
self.assertEqual(record.index, 0)
570570

571-
@unittest.expectedFailure # TODO: RUSTPYTHON
572571
def test_trace(self):
573572
self.assertEqual(len(git.tr), 3)
574573
frame1, frame2, frame3, = git.tr

Lib/test/test_named_expressions.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,24 @@ def test_named_expression_invalid_06(self):
4444
with self.assertRaisesRegex(SyntaxError, "cannot use assignment expressions with tuple"):
4545
exec(code, {}, {})
4646

47-
# TODO: RUSTPYTHON: wrong error message
48-
@unittest.expectedFailure
4947
def test_named_expression_invalid_07(self):
5048
code = """def spam(a = b := 42): pass"""
5149

5250
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
5351
exec(code, {}, {})
5452

55-
# TODO: RUSTPYTHON: wrong error message
56-
@unittest.expectedFailure
5753
def test_named_expression_invalid_08(self):
5854
code = """def spam(a: b := 42 = 5): pass"""
5955

6056
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
6157
exec(code, {}, {})
6258

63-
# TODO: RUSTPYTHON: wrong error message
64-
@unittest.expectedFailure
6559
def test_named_expression_invalid_09(self):
6660
code = """spam(a=b := 'c')"""
6761

6862
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
6963
exec(code, {}, {})
7064

71-
# TODO: RUSTPYTHON: wrong error message
72-
@unittest.expectedFailure
7365
def test_named_expression_invalid_10(self):
7466
code = """spam(x = y := f(x))"""
7567

@@ -103,8 +95,6 @@ def test_named_expression_invalid_13(self):
10395
"positional argument follows keyword argument"):
10496
exec(code, {}, {})
10597

106-
# TODO: RUSTPYTHON: wrong error message
107-
@unittest.expectedFailure
10898
def test_named_expression_invalid_14(self):
10999
code = """(x := lambda: y := 1)"""
110100

@@ -120,8 +110,6 @@ def test_named_expression_invalid_15(self):
120110
"cannot use assignment expressions with lambda"):
121111
exec(code, {}, {})
122112

123-
# TODO: RUSTPYTHON: wrong error message
124-
@unittest.expectedFailure
125113
def test_named_expression_invalid_16(self):
126114
code = "[i + 1 for i in i := [1,2]]"
127115

Lib/test/test_syntax.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,6 @@ def test_expression_with_assignment(self):
22932293
offset=7
22942294
)
22952295

2296-
@unittest.expectedFailure # TODO: RUSTPYTHON
22972296
def test_curly_brace_after_primary_raises_immediately(self):
22982297
self._check_error("f{}", "invalid syntax", mode="single")
22992298

Lib/test/test_sys.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ def test_original_excepthook(self):
176176

177177
self.assertRaises(TypeError, sys.__excepthook__)
178178

179-
@unittest.expectedFailure # TODO: RUSTPYTHON; SyntaxError formatting in arbitrary tracebacks
180179
@force_not_colorized
181180
def test_excepthook_bytes_filename(self):
182181
# bpo-37467: sys.excepthook() must not crash if a filename

0 commit comments

Comments
 (0)