Skip to content
This repository was archived by the owner on May 11, 2023. It is now read-only.

Commit 2a1b2ed

Browse files
authored
Merge pull request RustPython#4839 from Masorubka1/test_list.py
Update test_list.py from Cpython v3.11.2
2 parents 12d288f + 889df33 commit 2a1b2ed

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

Lib/test/test_list.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ def test_basic(self):
2020
self.assertEqual(list(x for x in range(10) if x % 2),
2121
[1, 3, 5, 7, 9])
2222

23-
# XXX RUSTPYTHON TODO: catch ooms
24-
if sys.maxsize == 0x7fffffff and False:
23+
if sys.maxsize == 0x7fffffff:
2524
# This test can currently only work on 32-bit machines.
26-
# XXX If/when PySequence_Length() returns a ssize_t, it should be
27-
# XXX re-enabled.
2825
# Verify clearing of bug #556025.
2926
# This assumes that the max data size (sys.maxint) == max
3027
# address size this also assumes that the address size is at
@@ -47,6 +44,36 @@ def test_keyword_args(self):
4744
with self.assertRaisesRegex(TypeError, 'keyword argument'):
4845
list(sequence=[])
4946

47+
# TODO: RUSTPYTHON
48+
@unittest.expectedFailure
49+
def test_keywords_in_subclass(self):
50+
class subclass(list):
51+
pass
52+
u = subclass([1, 2])
53+
self.assertIs(type(u), subclass)
54+
self.assertEqual(list(u), [1, 2])
55+
with self.assertRaises(TypeError):
56+
subclass(sequence=())
57+
58+
class subclass_with_init(list):
59+
def __init__(self, seq, newarg=None):
60+
super().__init__(seq)
61+
self.newarg = newarg
62+
u = subclass_with_init([1, 2], newarg=3)
63+
self.assertIs(type(u), subclass_with_init)
64+
self.assertEqual(list(u), [1, 2])
65+
self.assertEqual(u.newarg, 3)
66+
67+
class subclass_with_new(list):
68+
def __new__(cls, seq, newarg=None):
69+
self = super().__new__(cls, seq)
70+
self.newarg = newarg
71+
return self
72+
u = subclass_with_new([1, 2], newarg=3)
73+
self.assertIs(type(u), subclass_with_new)
74+
self.assertEqual(list(u), [1, 2])
75+
self.assertEqual(u.newarg, 3)
76+
5077
def test_truth(self):
5178
super().test_truth()
5279
self.assertTrue(not [])
@@ -69,6 +96,21 @@ def imul(a, b): a *= b
6996
self.assertRaises((MemoryError, OverflowError), mul, lst, n)
7097
self.assertRaises((MemoryError, OverflowError), imul, lst, n)
7198

99+
# TODO: RUSTPYTHON
100+
@unittest.expectedFailure
101+
def test_list_resize_overflow(self):
102+
# gh-97616: test new_allocated * sizeof(PyObject*) overflow
103+
# check in list_resize()
104+
lst = [0] * 65
105+
del lst[1:]
106+
self.assertEqual(len(lst), 1)
107+
108+
size = ((2 ** (tuple.__itemsize__ * 8) - 1) // 2)
109+
with self.assertRaises((MemoryError, OverflowError)):
110+
lst * size
111+
with self.assertRaises((MemoryError, OverflowError)):
112+
lst *= size
113+
72114
def test_repr_large(self):
73115
# Check the repr of large list objects
74116
def check(n):
@@ -230,5 +272,6 @@ def __eq__(self, other):
230272
lst = [X(), X()]
231273
X() in lst
232274

275+
233276
if __name__ == "__main__":
234277
unittest.main()

0 commit comments

Comments
 (0)