Update some tests to 3.14.5 (#7909)

* Align patches for `test_class.py`

* Update more tests to 3.14.5

* Update `test_math`

* `test_hash.py`

* Update `test_grammar.py`

* Fix failing test

* Restore `test_grammar.py`
This commit is contained in:
Shahar Naveh authored and GitHub committed 2026-05-19 13:31:33 +09:00
1 parent ed4ee2442d
commit 292f66e051
8 files changed
+65 -29

No files matched your search

+3 -4
View File
@@ -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__):
@@ -903,7 +903,7 @@ class TestInlineValues(unittest.TestCase):
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)
@@ -1056,6 +1056,5 @@ class TestInlineValues(unittest.TestCase):
self.assertFalse(out, msg=out.decode('utf-8'))
self.assertFalse(err, msg=err.decode('utf-8'))
if __name__ == '__main__':
unittest.main()
+4 -8
View File
@@ -263,8 +263,7 @@ class StringlikeHashRandomizationTests(HashRandomizationTests):
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)
@@ -275,8 +274,7 @@ class StringlikeHashRandomizationTests(HashRandomizationTests):
# 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
@@ -284,8 +282,7 @@ class StringlikeHashRandomizationTests(HashRandomizationTests):
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:
@@ -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)
+28 -2
View File
@@ -43,6 +43,7 @@ from test.support import (
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,
@@ -1238,8 +1239,7 @@ os.does_not_exist
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:
@@ -2544,6 +2544,32 @@ class SubinterpImportTests(unittest.TestCase):
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.
+2
View File
@@ -324,6 +324,8 @@ class MathTests(unittest.TestCase):
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)
+22
View File
@@ -581,6 +581,28 @@ class ArrayMemoryviewTest(unittest.TestCase,
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):
+3 -11
View File
@@ -312,7 +312,7 @@ is *not* valid syntax.)
>>> 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
@@ -320,17 +320,9 @@ is *not* valid 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
+2 -3
View File
@@ -94,7 +94,7 @@ class TestPkg(unittest.TestCase):
def test_1(self):
hier = [("t1", None), ("t1 __init__.py", "")]
self.mkhier(hier)
import t1
import t1 # noqa: F401
def test_2(self):
hier = [
@@ -124,7 +124,7 @@ class TestPkg(unittest.TestCase):
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")
@@ -190,7 +190,6 @@ class TestPkg(unittest.TestCase):
]
self.mkhier(hier)
import t5
s = """
from t5 import *
self.assertEqual(dir(), ['foo', 'self', 'string', 't5'])
+1 -1
View File
@@ -326,7 +326,7 @@ class TestOptimizedCompares(unittest.TestCase):
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