1
1
import sys
2
+ import textwrap
2
3
from test import list_tests
3
4
from test .support import cpython_only
5
+ from test .support .script_helper import assert_python_ok
4
6
import pickle
5
7
import unittest
6
8
@@ -98,8 +100,13 @@ def imul(a, b): a *= b
98
100
self .assertRaises ((MemoryError , OverflowError ), mul , lst , n )
99
101
self .assertRaises ((MemoryError , OverflowError ), imul , lst , n )
100
102
103
+ def test_empty_slice (self ):
104
+ x = []
105
+ x [:] = x
106
+ self .assertEqual (x , [])
107
+
101
108
# TODO: RUSTPYTHON
102
- @unittest .skip ("Crashes on windows debug build " )
109
+ @unittest .skip ("TODO: RUSTPYTHON crash " )
103
110
def test_list_resize_overflow (self ):
104
111
# gh-97616: test new_allocated * sizeof(PyObject*) overflow
105
112
# check in list_resize()
@@ -113,13 +120,28 @@ def test_list_resize_overflow(self):
113
120
with self .assertRaises ((MemoryError , OverflowError )):
114
121
lst *= size
115
122
123
+ # TODO: RUSTPYTHON
124
+ @unittest .skip ("TODO: RUSTPYTHON hangs" )
125
+ def test_repr_mutate (self ):
126
+ class Obj :
127
+ @staticmethod
128
+ def __repr__ ():
129
+ try :
130
+ mylist .pop ()
131
+ except IndexError :
132
+ pass
133
+ return 'obj'
134
+
135
+ mylist = [Obj () for _ in range (5 )]
136
+ self .assertEqual (repr (mylist ), '[obj, obj, obj]' )
137
+
116
138
def test_repr_large (self ):
117
139
# Check the repr of large list objects
118
140
def check (n ):
119
141
l = [0 ] * n
120
142
s = repr (l )
121
143
self .assertEqual (s ,
122
- '[' + ', ' .join (['0' ] * n ) + ']' )
144
+ '[' + ', ' .join (['0' ] * n ) + ']' )
123
145
check (10 ) # check our checking code
124
146
check (1000000 )
125
147
@@ -302,6 +324,35 @@ def __eq__(self, other):
302
324
lst = [X (), X ()]
303
325
X () in lst
304
326
327
+ def test_tier2_invalidates_iterator (self ):
328
+ # GH-121012
329
+ for _ in range (100 ):
330
+ a = [1 , 2 , 3 ]
331
+ it = iter (a )
332
+ for _ in it :
333
+ pass
334
+ a .append (4 )
335
+ self .assertEqual (list (it ), [])
336
+
337
+ def test_deopt_from_append_list (self ):
338
+ # gh-132011: it used to crash, because
339
+ # of `CALL_LIST_APPEND` specialization failure.
340
+ code = textwrap .dedent ("""
341
+ l = []
342
+ def lappend(l, x, y):
343
+ l.append((x, y))
344
+ for x in range(3):
345
+ lappend(l, None, None)
346
+ try:
347
+ lappend(list, None, None)
348
+ except TypeError:
349
+ pass
350
+ else:
351
+ raise AssertionError
352
+ """ )
353
+
354
+ rc , _ , _ = assert_python_ok ("-c" , code )
355
+ self .assertEqual (rc , 0 )
305
356
306
357
if __name__ == "__main__" :
307
358
unittest .main ()
0 commit comments