Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,6 @@ def test_delattr(self):
msg = r"^attribute name must be string, not 'int'$"
self.assertRaisesRegex(TypeError, msg, delattr, sys, 1)

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: '__repr__' unexpectedly found in ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__firstlineno__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', 'bar']
def test_dir(self):
# dir(wrong number of arguments)
self.assertRaises(TypeError, dir, 42, 42)
Expand Down Expand Up @@ -989,7 +988,6 @@ def test_eval_builtins_mapping(self):
self.assertRaisesRegex(NameError, "name 'superglobal' is not defined",
eval, code, ns)

@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
def test_exec_builtins_mapping_import(self):
code = compile("import foo.bar", "test", "exec")
ns = {'__builtins__': types.MappingProxyType({})}
Expand All @@ -998,7 +996,6 @@ def test_exec_builtins_mapping_import(self):
exec(code, ns)
self.assertEqual(ns['foo'], ('foo.bar', ns, ns, None, 0))

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: AttributeError not raised by eval
def test_eval_builtins_mapping_reduce(self):
# list_iterator.__reduce__() calls _PyEval_GetBuiltin("iter")
code = compile("x.__reduce__()", "test", "eval")
Expand Down Expand Up @@ -2970,7 +2967,6 @@ def test_type_firstlineno(self):
A.__firstlineno__ = 43
self.assertEqual(A.__dict__['__firstlineno__'], 43)

@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: Expected type 'tuple' but 'str' found.
def test_type_typeparams(self):
class A[T]:
pass
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2788,7 +2788,6 @@ def test(klass):
with self.assertRaises(TypeError):
super(Base, kw=1)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_basic_inheritance(self):
# Testing inheritance from basic types...

Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_except_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,6 @@ def test_raise_handle_all_raise_two_unnamed(self):


class TestExceptStarExceptionGroupSubclass(ExceptStarTest):
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_except_star_EG_subclass(self):
class EG(ExceptionGroup):
def __new__(cls, message, excs, code):
Expand Down
3 changes: 0 additions & 3 deletions Lib/test/test_exception_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_exception_group_is_generic_type(self):


class BadConstructorArgs(unittest.TestCase):
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bad_EG_construction__too_many_args(self):
MSG = r'BaseExceptionGroup.__new__\(\) takes exactly 2 arguments'
with self.assertRaisesRegex(TypeError, MSG):
Expand Down Expand Up @@ -194,7 +193,6 @@ class MyEG(ExceptionGroup):
"MyEG('flat', [ValueError(1), TypeError(2)]), "
"TypeError(2)])"))

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: Tuples differ: ('test', (ValueError(1), TypeError(2))) != ('test', [])
def test_exceptions_mutation(self):
class MyEG(ExceptionGroup):
pass
Expand Down Expand Up @@ -236,7 +234,6 @@ class MyEG(ExceptionGroup):
"ExceptionGroup('test', deque([ValueError(1), TypeError(2)]))"
)

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: TypeError not raised
def test_repr_raises(self):
class MySeq(collections.abc.Sequence):
def __init__(self, raises):
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_exception_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def test_errno_translation(self):
self.assertEqual(e.strerror, "File already exists")
self.assertEqual(e.filename, "foo.txt")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_blockingioerror(self):
args = ("a", "b", "c", "d", "e")
for n in range(6):
Expand Down Expand Up @@ -181,7 +180,6 @@ def test_init_kwdargs(self):
self.assertEqual(e.bar, "baz")
self.assertEqual(e.args, ("some message",))

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_new_overridden(self):
e = SubOSErrorWithNew("some message", "baz")
self.assertEqual(e.baz, "baz")
Expand Down
18 changes: 0 additions & 18 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def raise_catch(self, exc, excname):
self.assertEqual(buf1, buf2)
self.assertEqual(exc.__name__, excname)

@unittest.expectedFailure # TODO: RUSTPYTHON
def testRaising(self):
self.raise_catch(AttributeError, "AttributeError")
self.assertRaises(AttributeError, getattr, sys, "undefined_attribute")
Expand Down Expand Up @@ -145,7 +144,6 @@ def testRaising(self):

self.raise_catch(StopAsyncIteration, "StopAsyncIteration")

@unittest.expectedFailure # TODO: RUSTPYTHON
def testSyntaxErrorMessage(self):
# make sure the right exception message is raised for each of
# these code fragments
Expand All @@ -170,7 +168,6 @@ def ckmsg(src, msg):
ckmsg("continue\n", "'continue' not properly in loop")
ckmsg("f'{6 0}'", "invalid syntax. Perhaps you forgot a comma?")

@unittest.expectedFailure # TODO: RUSTPYTHON
def testSyntaxErrorMissingParens(self):
def ckmsg(src, msg, exception=SyntaxError):
try:
Expand Down Expand Up @@ -235,7 +232,6 @@ def test_error_offset_continuation_characters(self):
check = self.check
check('"\\\n"(1 for c in I,\\\n\\', 2, 2)

@unittest.expectedFailure # TODO: RUSTPYTHON
def testSyntaxErrorOffset(self):
check = self.check
check('def fact(x):\n\treturn x!\n', 2, 10)
Expand Down Expand Up @@ -442,7 +438,6 @@ def test_windows_message(self):
with self.assertRaisesRegex(OSError, 'Windows Error 0x%x' % code):
ctypes.pythonapi.PyErr_SetFromWindowsErr(code)

@unittest.expectedFailure # TODO: RUSTPYTHON
def testAttributes(self):
# test that exception attributes are happy

Expand Down Expand Up @@ -661,7 +656,6 @@ def testInvalidTraceback(self):
else:
self.fail("No exception raised")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_invalid_setattr(self):
TE = TypeError
exc = Exception()
Expand All @@ -674,7 +668,6 @@ def test_invalid_setattr(self):
msg = "exception context must be None or derive from BaseException"
self.assertRaisesRegex(TE, msg, setattr, exc, '__context__', 1)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_invalid_delattr(self):
TE = TypeError
try:
Expand Down Expand Up @@ -1306,7 +1299,6 @@ def test_context_of_exception_in_else_and_finally(self):
self.assertIs(exc, oe)
self.assertIs(exc.__context__, ve)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_unicode_change_attributes(self):
# See issue 7309. This was a crasher.

Expand Down Expand Up @@ -1350,7 +1342,6 @@ def test_unicode_errors_no_object(self):
for klass in klasses:
self.assertEqual(str(klass.__new__(klass)), "")

@unittest.expectedFailure # TODO: RUSTPYTHON; OverflowError: Python int too large to convert to Rust usize
def test_unicode_error_str_does_not_crash(self):
# Test that str(UnicodeError(...)) does not crash.
# See https://github.com/python/cpython/issues/123378.
Expand All @@ -1374,13 +1365,11 @@ def test_unicode_error_str_does_not_crash(self):
exc = UnicodeDecodeError('utf-8', encoded, start, end, '')
self.assertIsInstance(str(exc), str)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_unicode_error_evil_str_set_none_object(self):
def side_effect(exc):
exc.object = None
self.do_test_unicode_error_mutate(side_effect)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_unicode_error_evil_str_del_self_object(self):
def side_effect(exc):
del exc.object
Expand Down Expand Up @@ -2054,7 +2043,6 @@ def blech(self):

class ImportErrorTests(unittest.TestCase):

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_attributes(self):
# Setting 'name' and 'path' should not be a problem.
exc = ImportError('test')
Expand Down Expand Up @@ -2402,14 +2390,12 @@ def test_encodings(self):
self.assertEqual(err[-3], ' (')
self.assertEqual(err[-2], ' ^')

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_non_utf8(self):
# Check non utf-8 characters
self.addCleanup(unlink, TESTFN)
err = run_script(b"\x89")
self.assertIn("SyntaxError: Non-UTF-8 code starting with '\\x89' in file", err[-1])

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_source(self):
def try_compile(source):
with self.assertRaises(SyntaxError) as cm:
Expand Down Expand Up @@ -2524,7 +2510,6 @@ def test_incorrect_constructor(self):
args = ("bad.py", 1, 2, "abcdefg", 1)
self.assertRaises(TypeError, SyntaxError, "bad bad", args)

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 2 is not None
def test_syntax_error_memory_leak(self):
# gh-146250: memory leak with re-initialization of SyntaxError
e = SyntaxError("msg", ("file.py", 1, 2, "txt", 2, 3))
Expand Down Expand Up @@ -2600,7 +2585,6 @@ def in_except():
pass
self.lineno_after_raise(in_except, 4)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_lineno_after_other_except(self):
def other_except():
try:
Expand All @@ -2618,7 +2602,6 @@ def in_named_except():
pass
self.lineno_after_raise(in_named_except, 4)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_lineno_in_try(self):
def in_try():
try:
Expand Down Expand Up @@ -2657,7 +2640,6 @@ def after_with():
pass
self.lineno_after_raise(after_with, 2)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_missing_lineno_shows_as_none(self):
def f():
1/0
Expand Down
7 changes: 3 additions & 4 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ def test_post_mortem():
... test_function_2()
... print('Not reached.')

>>> with PdbTestInput([ # TODO: RUSTPYTHON # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE +EXPECTED_FAILURE
>>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
... 'step', # step to test_function_2() line
... 'next', # step over exception-raising call
... 'bt', # get a backtrace
Expand Down Expand Up @@ -2806,7 +2806,7 @@ def test_pdb_closure():
... g = 3
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()

>>> with PdbTestInput([ # TODO: RUSTPYTHON # doctest: +NORMALIZE_WHITESPACE +EXPECTED_FAILURE
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
... 'k',
... 'g',
... 'y = y',
Expand Down Expand Up @@ -3224,7 +3224,7 @@ def test_pdb_issue_gh_127321():
... import pdb; pdb_instance = pdb.Pdb(nosigint=True, readrc=False)
... [1, 2] and pdb_instance.set_trace()
... a = 1
>>> with PdbTestInput([ # TODO: RUSTPYTHON # doctest: +NORMALIZE_WHITESPACE +EXPECTED_FAILURE
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
... 'continue'
... ]):
... test_function()
Expand Down Expand Up @@ -4575,7 +4575,6 @@ def _create_fake_frozen_module():
self.assertIn('4 B', stdout, "breakpoint not found")
self.assertIn('-> def func():', stdout, "stack entry not found")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_empty_file(self):
script = ''
commands = 'q\n'
Expand Down
3 changes: 0 additions & 3 deletions Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,6 @@ def format(fmt, *values):
self.assertEqual(format('x = %s!', '%% %s'), 'x = %% %s!')
self.assertEqual(format('x = %s, y = %d', 12, 34), 'x = 12, y = 34')

@unittest.expectedFailure # TODO: RUSTPYTHON; ValueError: unsupported format character 'z' (0x7a) at index 3
def test_format_errors(self):
with self.assertRaisesRegex(TypeError,
'not enough arguments for format string'):
Expand Down Expand Up @@ -1006,7 +1005,6 @@ def trace(frame, event, arg):
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
self.assertEqual(f.__code__.co_code, co_code)

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: RuntimeWarning not triggered
def test_setting_lineno_one_undefined(self):
code = textwrap.dedent("""\
def f():
Expand Down Expand Up @@ -1041,7 +1039,6 @@ def trace(frame, event, arg):
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
self.assertEqual(f.__code__.co_code, co_code)

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: RuntimeWarning not triggered
def test_setting_lineno_two_undefined(self):
code = textwrap.dedent("""\
def f():
Expand Down
6 changes: 0 additions & 6 deletions Lib/test/test_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class TestPy2MigrationHint(unittest.TestCase):
if print statement is executed as in Python 2.
"""

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_normal_string(self):
python2_print_str = 'print "Hello World"'
with self.assertRaises(SyntaxError) as context:
Expand All @@ -155,7 +154,6 @@ def test_normal_string(self):
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
str(context.exception))

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_with_soft_space(self):
python2_print_str = 'print "Hello World",'
with self.assertRaises(SyntaxError) as context:
Expand All @@ -164,7 +162,6 @@ def test_string_with_soft_space(self):
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
str(context.exception))

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_with_excessive_whitespace(self):
python2_print_str = 'print "Hello World", '
with self.assertRaises(SyntaxError) as context:
Expand All @@ -173,7 +170,6 @@ def test_string_with_excessive_whitespace(self):
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
str(context.exception))

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_with_leading_whitespace(self):
python2_print_str = '''if 1:
print "Hello World"
Expand All @@ -187,7 +183,6 @@ def test_string_with_leading_whitespace(self):
# bpo-32685: Suggestions for print statement should be proper when
# it is in the same line as the header of a compound statement
# and/or followed by a semicolon
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_with_semicolon(self):
python2_print_str = 'print p;'
with self.assertRaises(SyntaxError) as context:
Expand All @@ -196,7 +191,6 @@ def test_string_with_semicolon(self):
self.assertIn("Missing parentheses in call to 'print'. Did you mean print(...)",
str(context.exception))

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_string_in_loop_on_same_line(self):
python2_print_str = 'for i in s: print i'
with self.assertRaises(SyntaxError) as context:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@
...
SyntaxError: name 'x' is parameter and nonlocal

>>> def f(): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
>>> def f():
... global x
... nonlocal x
Traceback (most recent call last):
Expand Down
18 changes: 13 additions & 5 deletions crates/capi/src/pyerrors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::convert::Infallible;
use core::ffi::{c_char, c_int};
use core::ptr::NonNull;
use core::slice;
use rustpython_vm::builtins::{PyBaseException, PyTuple, PyType};
use rustpython_vm::builtins::{PyBaseException, PyTraceback, PyTuple, PyType};
use rustpython_vm::convert::IntoObject;
use rustpython_vm::exceptions::ExceptionZoo;
use rustpython_vm::{AsObject, PyObjectRef, PyResult};
Expand Down Expand Up @@ -298,7 +298,7 @@ pub unsafe extern "C" fn PyException_SetCause(exc: *mut PyObject, cause: *mut Py
let exc = unsafe { &*exc }.try_downcast_ref::<PyBaseException>(vm)?;
let cause = NonNull::new(cause)
.map(|obj| unsafe { PyObjectRef::from_raw(obj).downcast_unchecked() });
exc.set___cause__(cause);
exc.set_cause(cause);
Ok(())
})
}
Expand All @@ -309,7 +309,7 @@ pub unsafe extern "C" fn PyException_SetContext(exc: *mut PyObject, context: *mu
let exc = unsafe { &*exc }.try_downcast_ref::<PyBaseException>(vm)?;
let context = NonNull::new(context)
.map(|obj| unsafe { PyObjectRef::from_raw(obj).downcast_unchecked() });
exc.set___context__(context);
exc.set_context(context);
Ok(())
})
}
Expand Down Expand Up @@ -362,8 +362,16 @@ pub unsafe extern "C" fn PyUnicodeDecodeError_Create(
pub unsafe extern "C" fn PyException_SetTraceback(exc: *mut PyObject, tb: *mut PyObject) -> c_int {
with_vm(|vm| {
let exc = unsafe { &*exc }.try_downcast_ref::<PyBaseException>(vm)?;
let traceback = unsafe { tb.as_ref() }.map(|obj| obj.to_owned());
exc.set___traceback__(vm.unwrap_or_none(traceback), vm)
let traceback = match unsafe { tb.as_ref() }.map(|obj| obj.to_owned()) {
None => None,
Some(obj) if vm.is_none(&obj) => None,
Some(obj) => Some(
obj.downcast::<PyTraceback>()
.map_err(|_| vm.new_type_error("__traceback__ must be a traceback or None"))?,
),
};
exc.set_traceback(traceback);
Ok(())
})
}

Expand Down
Loading
Loading