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
7 changes: 3 additions & 4 deletions Lib/test/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,14 @@ class VarSizedSubclass(tuple):

class TestInlineValues(unittest.TestCase):

@unittest.expectedFailure # TODO: RUSTPYTHON; NameError: name 'has_inline_values' is not defined.
@unittest.expectedFailure # TODO: RUSTPYTHON; NameError: name 'has_inline_values' is not defined.
def test_no_flags_for_slots_class(self):
flags = NoManagedDict.__flags__
self.assertEqual(flags & Py_TPFLAGS_MANAGED_DICT, 0)
self.assertEqual(flags & Py_TPFLAGS_INLINE_VALUES, 0)
self.assertFalse(has_inline_values(NoManagedDict()))

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 0 != 4
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 0 != 4
def test_both_flags_for_regular_class(self):
for cls in (Plain, WithAttrs):
with self.subTest(cls=cls.__name__):
Expand All @@ -903,7 +903,7 @@ def test_both_flags_for_regular_class(self):
self.assertEqual(flags & Py_TPFLAGS_INLINE_VALUES, Py_TPFLAGS_INLINE_VALUES)
self.assertTrue(has_inline_values(cls()))

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 0 != 4
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 0 != 4
def test_managed_dict_only_for_varsized_subclass(self):
flags = VarSizedSubclass.__flags__
self.assertEqual(flags & Py_TPFLAGS_MANAGED_DICT, Py_TPFLAGS_MANAGED_DICT)
Expand Down Expand Up @@ -1056,6 +1056,5 @@ def __init__(self):
self.assertFalse(out, msg=out.decode('utf-8'))
self.assertFalse(err, msg=err.decode('utf-8'))


if __name__ == '__main__':
unittest.main()
12 changes: 4 additions & 8 deletions Lib/test/test_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ def get_expected_hash(self, position, length):
platform = 3 if IS_64BIT else 2
return self.known_hashes[algorithm][position][platform]

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_null_hash(self):
# PYTHONHASHSEED=0 disables the randomized hash
known_hash_of_obj = self.get_expected_hash(0, 3)
Expand All @@ -275,17 +274,15 @@ def test_null_hash(self):
# It can also be disabled by setting the seed to 0:
self.assertEqual(self.get_hash(self.repr_, seed=0), known_hash_of_obj)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
@skip_unless_internalhash
def test_fixed_hash(self):
# test a fixed seed for the randomized hash
# Note that all types share the same values:
h = self.get_expected_hash(1, 3)
self.assertEqual(self.get_hash(self.repr_, seed=42), h)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
@skip_unless_internalhash
def test_long_fixed_hash(self):
if self.repr_long is None:
Expand All @@ -304,8 +301,7 @@ class StrHashRandomizationTests(StringlikeHashRandomizationTests,
def test_empty_string(self):
self.assertEqual(hash(""), 0)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
@skip_unless_internalhash
def test_ucs2_string(self):
h = self.get_expected_hash(3, 6)
Expand Down
30 changes: 28 additions & 2 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Py_GIL_DISABLED,
no_rerun,
force_not_colorized_test_class,
catch_unraisable_exception
)
from test.support.import_helper import (
forget, make_legacy_pyc, unlink, unload, ready_to_import,
Expand Down Expand Up @@ -1238,8 +1239,7 @@ def test_script_shadowing_stdlib_sys_path_modification(self):
stdout, stderr = popen.communicate()
self.assertRegex(stdout, expected_error)

# TODO: RUSTPYTHON: _imp.create_dynamic is for C extensions, not applicable
@unittest.skip("TODO: RustPython _imp.create_dynamic not implemented")
@unittest.expectedFailure # TODO: RUSTPYTHON; _imp.create_dynamic not implemented
def test_create_dynamic_null(self):
with self.assertRaisesRegex(ValueError, 'embedded null character'):
class Spec:
Expand Down Expand Up @@ -2544,6 +2544,32 @@ def test_disallowed_reimport(self):
excsnap = _interpreters.run_string(interpid, script)
self.assertIsNot(excsnap, None)

@requires_subinterpreters
def test_pyinit_function_raises_exception(self):
# gh-144601: PyInit functions that raised exceptions would cause a
# crash when imported from a subinterpreter.
import _testsinglephase
filename = _testsinglephase.__file__
script = f"""if True:
from test.test_import import import_extension_from_file

import_extension_from_file('_testsinglephase_raise_exception', {filename!r})"""

interp = _interpreters.create()
try:
with catch_unraisable_exception() as cm:
exception = _interpreters.run_string(interp, script)
unraisable = cm.unraisable
finally:
_interpreters.destroy(interp)

self.assertIsNotNone(exception)
self.assertIsNotNone(exception.type.__name__, "ImportError")
self.assertIsNotNone(exception.msg, "failed to import from subinterpreter due to exception")
self.assertIsNotNone(unraisable)
self.assertIs(unraisable.exc_type, RuntimeError)
self.assertEqual(str(unraisable.exc_value), "evil")


class TestSinglePhaseSnapshot(ModuleSnapshot):
"""A representation of a single-phase init module for testing.
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ def testAtanh(self):
self.assertRaises(ValueError, math.atanh, NINF)
self.assertTrue(math.isnan(math.atanh(NAN)))

@unittest.skipIf(sys.platform.startswith("sunos"),
"skipping, see gh-138573")
def testAtan2(self):
self.assertRaises(TypeError, math.atan2)
self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2)
Expand Down
22 changes: 22 additions & 0 deletions Lib/test/test_memoryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,28 @@ def test_array_assign(self):
m[:] = new_a
self.assertEqual(a, new_a)

def test_boolean_format(self):
# Test '?' format (keep all the checks below for UBSan)
# See github.com/python/cpython/issues/148390.

# m1a and m1b are equivalent to [False, True, False]
m1a = memoryview(b'\0\2\0').cast('?')
self.assertEqual(m1a.tolist(), [False, True, False])
m1b = memoryview(b'\0\4\0').cast('?')
self.assertEqual(m1b.tolist(), [False, True, False])
self.assertEqual(m1a, m1b)

# m2a and m2b are equivalent to [True, True, True]
m2a = memoryview(b'\1\3\5').cast('?')
self.assertEqual(m2a.tolist(), [True, True, True])
m2b = memoryview(b'\2\4\6').cast('?')
self.assertEqual(m2b.tolist(), [True, True, True])
self.assertEqual(m2a, m2b)

allbytes = bytes(range(256))
allbytes = memoryview(allbytes).cast('?')
self.assertEqual(allbytes.tolist(), [False] + [True] * 255)


class BytesMemorySliceTest(unittest.TestCase,
BaseMemorySliceTests, BaseBytesMemoryTests):
Expand Down
14 changes: 3 additions & 11 deletions Lib/test/test_pep646_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,25 +312,17 @@
>>> f4.__annotations__
{'args': StarredB, 'arg1': <class 'int'>}

>>> def f5(*args: *b = (1,)): pass # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE
>>> def f5(*args: *b = (1,)): pass # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE
Traceback (most recent call last):
...
SyntaxError: invalid syntax
"""

__test__ = {'doctests' : doctests}

EXPECTED_FAILURE = doctest.register_optionflag('EXPECTED_FAILURE') # TODO: RUSTPYTHON
class CustomOutputChecker(doctest.OutputChecker): # TODO: RUSTPYTHON
def check_output(self, want, got, optionflags): # TODO: RUSTPYTHON
if optionflags & EXPECTED_FAILURE: # TODO: RUSTPYTHON
if want == got: # TODO: RUSTPYTHON
return False # TODO: RUSTPYTHON
return True # TODO: RUSTPYTHON
return super().check_output(want, got, optionflags) # TODO: RUSTPYTHON

def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite(checker=CustomOutputChecker())) # TODO: RUSTPYTHON
from test.support.rustpython import DocTestChecker # TODO: RUSTPYTHON
tests.addTest(doctest.DocTestSuite(checker=DocTestChecker())) # TODO: RUSTPYTHON
return tests


Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def mkhier(self, descr):
def test_1(self):
hier = [("t1", None), ("t1 __init__.py", "")]
self.mkhier(hier)
import t1
import t1 # noqa: F401

def test_2(self):
hier = [
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_2(self):

from t2 import sub
from t2.sub import subsub
from t2.sub.subsub import spam
from t2.sub.subsub import spam # noqa: F401
self.assertEqual(sub.__name__, "t2.sub")
self.assertEqual(subsub.__name__, "t2.sub.subsub")
self.assertEqual(sub.subsub.__name__, "t2.sub.subsub")
Expand Down Expand Up @@ -190,7 +190,6 @@ def test_5(self):
]
self.mkhier(hier)

import t5
s = """
from t5 import *
self.assertEqual(dir(), ['foo', 'self', 'string', 't5'])
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def test_safe_object_compare(self):
for L in float_int_lists:
check_against_PyObject_RichCompareBool(self, L)

@support.cpython_only # XXX RUSTPYTHON: added by us but it seems like an implementation detail
@unittest.skip("TODO: RUSTPYTHON; not really a todo, it seems like an implementation detail")
def test_unsafe_object_compare(self):

# This test is by ppperry. It ensures that unsafe_object_compare is
Expand Down
Loading