diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 1aee6fb73d2..f2f99d366d9 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -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 @@ 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) @@ -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() diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py index 9fae17db7b1..11c43ccee19 100644 --- a/Lib/test/test_hash.py +++ b/Lib/test/test_hash.py @@ -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) @@ -275,8 +274,7 @@ 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 @@ -284,8 +282,7 @@ def test_fixed_hash(self): 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) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 6920cf45533..60413aa7629 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -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, @@ -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: @@ -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. diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index d8a5eb27501..5678536ff18 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -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) diff --git a/Lib/test/test_memoryview.py b/Lib/test/test_memoryview.py index 891c4d76745..7889fa88d00 100644 --- a/Lib/test/test_memoryview.py +++ b/Lib/test/test_memoryview.py @@ -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): diff --git a/Lib/test/test_pep646_syntax.py b/Lib/test/test_pep646_syntax.py index ca8e7d62057..8034bb9e935 100644 --- a/Lib/test/test_pep646_syntax.py +++ b/Lib/test/test_pep646_syntax.py @@ -312,7 +312,7 @@ >>> f4.__annotations__ {'args': StarredB, 'arg1': } - >>> 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 @@ __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 diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py index eed0fd1c6b7..d2b724db40d 100644 --- a/Lib/test/test_pkg.py +++ b/Lib/test/test_pkg.py @@ -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 = [ @@ -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") @@ -190,7 +190,6 @@ def test_5(self): ] self.mkhier(hier) - import t5 s = """ from t5 import * self.assertEqual(dir(), ['foo', 'self', 'string', 't5']) diff --git a/Lib/test/test_sort.py b/Lib/test/test_sort.py index dfb050a34ec..3a6f4f1c05b 100644 --- a/Lib/test/test_sort.py +++ b/Lib/test/test_sort.py @@ -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