From ba6a81571148548eb2cf723696b4e363ed61f69c Mon Sep 17 00:00:00 2001 From: Andrey Maltsev Date: Tue, 4 Apr 2023 09:56:10 +0000 Subject: [PATCH 1/2] Update test_list.py from Cpython v3.11.2 --- Lib/test/test_list.py | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index da2857df92..4fa9bd95b8 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -21,7 +21,7 @@ def test_basic(self): [1, 3, 5, 7, 9]) # XXX RUSTPYTHON TODO: catch ooms - if sys.maxsize == 0x7fffffff and False: + if sys.maxsize == 0x7fffffff: # This test can currently only work on 32-bit machines. # XXX If/when PySequence_Length() returns a ssize_t, it should be # XXX re-enabled. @@ -47,6 +47,36 @@ def test_keyword_args(self): with self.assertRaisesRegex(TypeError, 'keyword argument'): list(sequence=[]) + # TODO: RUSTPYTHON + @unittest.expectedFailure + def test_keywords_in_subclass(self): + class subclass(list): + pass + u = subclass([1, 2]) + self.assertIs(type(u), subclass) + self.assertEqual(list(u), [1, 2]) + with self.assertRaises(TypeError): + subclass(sequence=()) + + class subclass_with_init(list): + def __init__(self, seq, newarg=None): + super().__init__(seq) + self.newarg = newarg + u = subclass_with_init([1, 2], newarg=3) + self.assertIs(type(u), subclass_with_init) + self.assertEqual(list(u), [1, 2]) + self.assertEqual(u.newarg, 3) + + class subclass_with_new(list): + def __new__(cls, seq, newarg=None): + self = super().__new__(cls, seq) + self.newarg = newarg + return self + u = subclass_with_new([1, 2], newarg=3) + self.assertIs(type(u), subclass_with_new) + self.assertEqual(list(u), [1, 2]) + self.assertEqual(u.newarg, 3) + def test_truth(self): super().test_truth() self.assertTrue(not []) @@ -69,6 +99,21 @@ def imul(a, b): a *= b self.assertRaises((MemoryError, OverflowError), mul, lst, n) self.assertRaises((MemoryError, OverflowError), imul, lst, n) + # TODO: RUSTPYTHON + @unittest.expectedFailure + def test_list_resize_overflow(self): + # gh-97616: test new_allocated * sizeof(PyObject*) overflow + # check in list_resize() + lst = [0] * 65 + del lst[1:] + self.assertEqual(len(lst), 1) + + size = ((2 ** (tuple.__itemsize__ * 8) - 1) // 2) + with self.assertRaises((MemoryError, OverflowError)): + lst * size + with self.assertRaises((MemoryError, OverflowError)): + lst *= size + def test_repr_large(self): # Check the repr of large list objects def check(n): @@ -230,5 +275,6 @@ def __eq__(self, other): lst = [X(), X()] X() in lst + if __name__ == "__main__": unittest.main() From 889df336d60db070c3f15950ed4b6cad031b7cdd Mon Sep 17 00:00:00 2001 From: Andrey Maltsev Date: Mon, 10 Apr 2023 14:16:12 +0000 Subject: [PATCH 2/2] fixes --- Lib/test/test_list.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index 4fa9bd95b8..575a77db0b 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -20,11 +20,8 @@ def test_basic(self): self.assertEqual(list(x for x in range(10) if x % 2), [1, 3, 5, 7, 9]) - # XXX RUSTPYTHON TODO: catch ooms if sys.maxsize == 0x7fffffff: # This test can currently only work on 32-bit machines. - # XXX If/when PySequence_Length() returns a ssize_t, it should be - # XXX re-enabled. # Verify clearing of bug #556025. # This assumes that the max data size (sys.maxint) == max # address size this also assumes that the address size is at