1 | n/a | """ |
---|
2 | n/a | Tests common to tuple, list and UserList.UserList |
---|
3 | n/a | """ |
---|
4 | n/a | |
---|
5 | n/a | import unittest |
---|
6 | n/a | import sys |
---|
7 | n/a | import pickle |
---|
8 | n/a | from test import support |
---|
9 | n/a | |
---|
10 | n/a | # Various iterables |
---|
11 | n/a | # This is used for checking the constructor (here and in test_deque.py) |
---|
12 | n/a | def iterfunc(seqn): |
---|
13 | n/a | 'Regular generator' |
---|
14 | n/a | for i in seqn: |
---|
15 | n/a | yield i |
---|
16 | n/a | |
---|
17 | n/a | class Sequence: |
---|
18 | n/a | 'Sequence using __getitem__' |
---|
19 | n/a | def __init__(self, seqn): |
---|
20 | n/a | self.seqn = seqn |
---|
21 | n/a | def __getitem__(self, i): |
---|
22 | n/a | return self.seqn[i] |
---|
23 | n/a | |
---|
24 | n/a | class IterFunc: |
---|
25 | n/a | 'Sequence using iterator protocol' |
---|
26 | n/a | def __init__(self, seqn): |
---|
27 | n/a | self.seqn = seqn |
---|
28 | n/a | self.i = 0 |
---|
29 | n/a | def __iter__(self): |
---|
30 | n/a | return self |
---|
31 | n/a | def __next__(self): |
---|
32 | n/a | if self.i >= len(self.seqn): raise StopIteration |
---|
33 | n/a | v = self.seqn[self.i] |
---|
34 | n/a | self.i += 1 |
---|
35 | n/a | return v |
---|
36 | n/a | |
---|
37 | n/a | class IterGen: |
---|
38 | n/a | 'Sequence using iterator protocol defined with a generator' |
---|
39 | n/a | def __init__(self, seqn): |
---|
40 | n/a | self.seqn = seqn |
---|
41 | n/a | self.i = 0 |
---|
42 | n/a | def __iter__(self): |
---|
43 | n/a | for val in self.seqn: |
---|
44 | n/a | yield val |
---|
45 | n/a | |
---|
46 | n/a | class IterNextOnly: |
---|
47 | n/a | 'Missing __getitem__ and __iter__' |
---|
48 | n/a | def __init__(self, seqn): |
---|
49 | n/a | self.seqn = seqn |
---|
50 | n/a | self.i = 0 |
---|
51 | n/a | def __next__(self): |
---|
52 | n/a | if self.i >= len(self.seqn): raise StopIteration |
---|
53 | n/a | v = self.seqn[self.i] |
---|
54 | n/a | self.i += 1 |
---|
55 | n/a | return v |
---|
56 | n/a | |
---|
57 | n/a | class IterNoNext: |
---|
58 | n/a | 'Iterator missing __next__()' |
---|
59 | n/a | def __init__(self, seqn): |
---|
60 | n/a | self.seqn = seqn |
---|
61 | n/a | self.i = 0 |
---|
62 | n/a | def __iter__(self): |
---|
63 | n/a | return self |
---|
64 | n/a | |
---|
65 | n/a | class IterGenExc: |
---|
66 | n/a | 'Test propagation of exceptions' |
---|
67 | n/a | def __init__(self, seqn): |
---|
68 | n/a | self.seqn = seqn |
---|
69 | n/a | self.i = 0 |
---|
70 | n/a | def __iter__(self): |
---|
71 | n/a | return self |
---|
72 | n/a | def __next__(self): |
---|
73 | n/a | 3 // 0 |
---|
74 | n/a | |
---|
75 | n/a | class IterFuncStop: |
---|
76 | n/a | 'Test immediate stop' |
---|
77 | n/a | def __init__(self, seqn): |
---|
78 | n/a | pass |
---|
79 | n/a | def __iter__(self): |
---|
80 | n/a | return self |
---|
81 | n/a | def __next__(self): |
---|
82 | n/a | raise StopIteration |
---|
83 | n/a | |
---|
84 | n/a | from itertools import chain |
---|
85 | n/a | def itermulti(seqn): |
---|
86 | n/a | 'Test multiple tiers of iterators' |
---|
87 | n/a | return chain(map(lambda x:x, iterfunc(IterGen(Sequence(seqn))))) |
---|
88 | n/a | |
---|
89 | n/a | class LyingTuple(tuple): |
---|
90 | n/a | def __iter__(self): |
---|
91 | n/a | yield 1 |
---|
92 | n/a | |
---|
93 | n/a | class LyingList(list): |
---|
94 | n/a | def __iter__(self): |
---|
95 | n/a | yield 1 |
---|
96 | n/a | |
---|
97 | n/a | class CommonTest(unittest.TestCase): |
---|
98 | n/a | # The type to be tested |
---|
99 | n/a | type2test = None |
---|
100 | n/a | |
---|
101 | n/a | def test_constructors(self): |
---|
102 | n/a | l0 = [] |
---|
103 | n/a | l1 = [0] |
---|
104 | n/a | l2 = [0, 1] |
---|
105 | n/a | |
---|
106 | n/a | u = self.type2test() |
---|
107 | n/a | u0 = self.type2test(l0) |
---|
108 | n/a | u1 = self.type2test(l1) |
---|
109 | n/a | u2 = self.type2test(l2) |
---|
110 | n/a | |
---|
111 | n/a | uu = self.type2test(u) |
---|
112 | n/a | uu0 = self.type2test(u0) |
---|
113 | n/a | uu1 = self.type2test(u1) |
---|
114 | n/a | uu2 = self.type2test(u2) |
---|
115 | n/a | |
---|
116 | n/a | v = self.type2test(tuple(u)) |
---|
117 | n/a | class OtherSeq: |
---|
118 | n/a | def __init__(self, initseq): |
---|
119 | n/a | self.__data = initseq |
---|
120 | n/a | def __len__(self): |
---|
121 | n/a | return len(self.__data) |
---|
122 | n/a | def __getitem__(self, i): |
---|
123 | n/a | return self.__data[i] |
---|
124 | n/a | s = OtherSeq(u0) |
---|
125 | n/a | v0 = self.type2test(s) |
---|
126 | n/a | self.assertEqual(len(v0), len(s)) |
---|
127 | n/a | |
---|
128 | n/a | s = "this is also a sequence" |
---|
129 | n/a | vv = self.type2test(s) |
---|
130 | n/a | self.assertEqual(len(vv), len(s)) |
---|
131 | n/a | |
---|
132 | n/a | # Create from various iteratables |
---|
133 | n/a | for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)): |
---|
134 | n/a | for g in (Sequence, IterFunc, IterGen, |
---|
135 | n/a | itermulti, iterfunc): |
---|
136 | n/a | self.assertEqual(self.type2test(g(s)), self.type2test(s)) |
---|
137 | n/a | self.assertEqual(self.type2test(IterFuncStop(s)), self.type2test()) |
---|
138 | n/a | self.assertEqual(self.type2test(c for c in "123"), self.type2test("123")) |
---|
139 | n/a | self.assertRaises(TypeError, self.type2test, IterNextOnly(s)) |
---|
140 | n/a | self.assertRaises(TypeError, self.type2test, IterNoNext(s)) |
---|
141 | n/a | self.assertRaises(ZeroDivisionError, self.type2test, IterGenExc(s)) |
---|
142 | n/a | |
---|
143 | n/a | # Issue #23757 |
---|
144 | n/a | self.assertEqual(self.type2test(LyingTuple((2,))), self.type2test((1,))) |
---|
145 | n/a | self.assertEqual(self.type2test(LyingList([2])), self.type2test([1])) |
---|
146 | n/a | |
---|
147 | n/a | def test_truth(self): |
---|
148 | n/a | self.assertFalse(self.type2test()) |
---|
149 | n/a | self.assertTrue(self.type2test([42])) |
---|
150 | n/a | |
---|
151 | n/a | def test_getitem(self): |
---|
152 | n/a | u = self.type2test([0, 1, 2, 3, 4]) |
---|
153 | n/a | for i in range(len(u)): |
---|
154 | n/a | self.assertEqual(u[i], i) |
---|
155 | n/a | self.assertEqual(u[int(i)], i) |
---|
156 | n/a | for i in range(-len(u), -1): |
---|
157 | n/a | self.assertEqual(u[i], len(u)+i) |
---|
158 | n/a | self.assertEqual(u[int(i)], len(u)+i) |
---|
159 | n/a | self.assertRaises(IndexError, u.__getitem__, -len(u)-1) |
---|
160 | n/a | self.assertRaises(IndexError, u.__getitem__, len(u)) |
---|
161 | n/a | self.assertRaises(ValueError, u.__getitem__, slice(0,10,0)) |
---|
162 | n/a | |
---|
163 | n/a | u = self.type2test() |
---|
164 | n/a | self.assertRaises(IndexError, u.__getitem__, 0) |
---|
165 | n/a | self.assertRaises(IndexError, u.__getitem__, -1) |
---|
166 | n/a | |
---|
167 | n/a | self.assertRaises(TypeError, u.__getitem__) |
---|
168 | n/a | |
---|
169 | n/a | a = self.type2test([10, 11]) |
---|
170 | n/a | self.assertEqual(a[0], 10) |
---|
171 | n/a | self.assertEqual(a[1], 11) |
---|
172 | n/a | self.assertEqual(a[-2], 10) |
---|
173 | n/a | self.assertEqual(a[-1], 11) |
---|
174 | n/a | self.assertRaises(IndexError, a.__getitem__, -3) |
---|
175 | n/a | self.assertRaises(IndexError, a.__getitem__, 3) |
---|
176 | n/a | |
---|
177 | n/a | def test_getslice(self): |
---|
178 | n/a | l = [0, 1, 2, 3, 4] |
---|
179 | n/a | u = self.type2test(l) |
---|
180 | n/a | |
---|
181 | n/a | self.assertEqual(u[0:0], self.type2test()) |
---|
182 | n/a | self.assertEqual(u[1:2], self.type2test([1])) |
---|
183 | n/a | self.assertEqual(u[-2:-1], self.type2test([3])) |
---|
184 | n/a | self.assertEqual(u[-1000:1000], u) |
---|
185 | n/a | self.assertEqual(u[1000:-1000], self.type2test([])) |
---|
186 | n/a | self.assertEqual(u[:], u) |
---|
187 | n/a | self.assertEqual(u[1:None], self.type2test([1, 2, 3, 4])) |
---|
188 | n/a | self.assertEqual(u[None:3], self.type2test([0, 1, 2])) |
---|
189 | n/a | |
---|
190 | n/a | # Extended slices |
---|
191 | n/a | self.assertEqual(u[::], u) |
---|
192 | n/a | self.assertEqual(u[::2], self.type2test([0, 2, 4])) |
---|
193 | n/a | self.assertEqual(u[1::2], self.type2test([1, 3])) |
---|
194 | n/a | self.assertEqual(u[::-1], self.type2test([4, 3, 2, 1, 0])) |
---|
195 | n/a | self.assertEqual(u[::-2], self.type2test([4, 2, 0])) |
---|
196 | n/a | self.assertEqual(u[3::-2], self.type2test([3, 1])) |
---|
197 | n/a | self.assertEqual(u[3:3:-2], self.type2test([])) |
---|
198 | n/a | self.assertEqual(u[3:2:-2], self.type2test([3])) |
---|
199 | n/a | self.assertEqual(u[3:1:-2], self.type2test([3])) |
---|
200 | n/a | self.assertEqual(u[3:0:-2], self.type2test([3, 1])) |
---|
201 | n/a | self.assertEqual(u[::-100], self.type2test([4])) |
---|
202 | n/a | self.assertEqual(u[100:-100:], self.type2test([])) |
---|
203 | n/a | self.assertEqual(u[-100:100:], u) |
---|
204 | n/a | self.assertEqual(u[100:-100:-1], u[::-1]) |
---|
205 | n/a | self.assertEqual(u[-100:100:-1], self.type2test([])) |
---|
206 | n/a | self.assertEqual(u[-100:100:2], self.type2test([0, 2, 4])) |
---|
207 | n/a | |
---|
208 | n/a | # Test extreme cases with long ints |
---|
209 | n/a | a = self.type2test([0,1,2,3,4]) |
---|
210 | n/a | self.assertEqual(a[ -pow(2,128): 3 ], self.type2test([0,1,2])) |
---|
211 | n/a | self.assertEqual(a[ 3: pow(2,145) ], self.type2test([3,4])) |
---|
212 | n/a | |
---|
213 | n/a | def test_contains(self): |
---|
214 | n/a | u = self.type2test([0, 1, 2]) |
---|
215 | n/a | for i in u: |
---|
216 | n/a | self.assertIn(i, u) |
---|
217 | n/a | for i in min(u)-1, max(u)+1: |
---|
218 | n/a | self.assertNotIn(i, u) |
---|
219 | n/a | |
---|
220 | n/a | self.assertRaises(TypeError, u.__contains__) |
---|
221 | n/a | |
---|
222 | n/a | def test_contains_fake(self): |
---|
223 | n/a | class AllEq: |
---|
224 | n/a | # Sequences must use rich comparison against each item |
---|
225 | n/a | # (unless "is" is true, or an earlier item answered) |
---|
226 | n/a | # So instances of AllEq must be found in all non-empty sequences. |
---|
227 | n/a | def __eq__(self, other): |
---|
228 | n/a | return True |
---|
229 | n/a | __hash__ = None # Can't meet hash invariant requirements |
---|
230 | n/a | self.assertNotIn(AllEq(), self.type2test([])) |
---|
231 | n/a | self.assertIn(AllEq(), self.type2test([1])) |
---|
232 | n/a | |
---|
233 | n/a | def test_contains_order(self): |
---|
234 | n/a | # Sequences must test in-order. If a rich comparison has side |
---|
235 | n/a | # effects, these will be visible to tests against later members. |
---|
236 | n/a | # In this test, the "side effect" is a short-circuiting raise. |
---|
237 | n/a | class DoNotTestEq(Exception): |
---|
238 | n/a | pass |
---|
239 | n/a | class StopCompares: |
---|
240 | n/a | def __eq__(self, other): |
---|
241 | n/a | raise DoNotTestEq |
---|
242 | n/a | |
---|
243 | n/a | checkfirst = self.type2test([1, StopCompares()]) |
---|
244 | n/a | self.assertIn(1, checkfirst) |
---|
245 | n/a | checklast = self.type2test([StopCompares(), 1]) |
---|
246 | n/a | self.assertRaises(DoNotTestEq, checklast.__contains__, 1) |
---|
247 | n/a | |
---|
248 | n/a | def test_len(self): |
---|
249 | n/a | self.assertEqual(len(self.type2test()), 0) |
---|
250 | n/a | self.assertEqual(len(self.type2test([])), 0) |
---|
251 | n/a | self.assertEqual(len(self.type2test([0])), 1) |
---|
252 | n/a | self.assertEqual(len(self.type2test([0, 1, 2])), 3) |
---|
253 | n/a | |
---|
254 | n/a | def test_minmax(self): |
---|
255 | n/a | u = self.type2test([0, 1, 2]) |
---|
256 | n/a | self.assertEqual(min(u), 0) |
---|
257 | n/a | self.assertEqual(max(u), 2) |
---|
258 | n/a | |
---|
259 | n/a | def test_addmul(self): |
---|
260 | n/a | u1 = self.type2test([0]) |
---|
261 | n/a | u2 = self.type2test([0, 1]) |
---|
262 | n/a | self.assertEqual(u1, u1 + self.type2test()) |
---|
263 | n/a | self.assertEqual(u1, self.type2test() + u1) |
---|
264 | n/a | self.assertEqual(u1 + self.type2test([1]), u2) |
---|
265 | n/a | self.assertEqual(self.type2test([-1]) + u1, self.type2test([-1, 0])) |
---|
266 | n/a | self.assertEqual(self.type2test(), u2*0) |
---|
267 | n/a | self.assertEqual(self.type2test(), 0*u2) |
---|
268 | n/a | self.assertEqual(self.type2test(), u2*0) |
---|
269 | n/a | self.assertEqual(self.type2test(), 0*u2) |
---|
270 | n/a | self.assertEqual(u2, u2*1) |
---|
271 | n/a | self.assertEqual(u2, 1*u2) |
---|
272 | n/a | self.assertEqual(u2, u2*1) |
---|
273 | n/a | self.assertEqual(u2, 1*u2) |
---|
274 | n/a | self.assertEqual(u2+u2, u2*2) |
---|
275 | n/a | self.assertEqual(u2+u2, 2*u2) |
---|
276 | n/a | self.assertEqual(u2+u2, u2*2) |
---|
277 | n/a | self.assertEqual(u2+u2, 2*u2) |
---|
278 | n/a | self.assertEqual(u2+u2+u2, u2*3) |
---|
279 | n/a | self.assertEqual(u2+u2+u2, 3*u2) |
---|
280 | n/a | |
---|
281 | n/a | class subclass(self.type2test): |
---|
282 | n/a | pass |
---|
283 | n/a | u3 = subclass([0, 1]) |
---|
284 | n/a | self.assertEqual(u3, u3*1) |
---|
285 | n/a | self.assertIsNot(u3, u3*1) |
---|
286 | n/a | |
---|
287 | n/a | def test_iadd(self): |
---|
288 | n/a | u = self.type2test([0, 1]) |
---|
289 | n/a | u += self.type2test() |
---|
290 | n/a | self.assertEqual(u, self.type2test([0, 1])) |
---|
291 | n/a | u += self.type2test([2, 3]) |
---|
292 | n/a | self.assertEqual(u, self.type2test([0, 1, 2, 3])) |
---|
293 | n/a | u += self.type2test([4, 5]) |
---|
294 | n/a | self.assertEqual(u, self.type2test([0, 1, 2, 3, 4, 5])) |
---|
295 | n/a | |
---|
296 | n/a | u = self.type2test("spam") |
---|
297 | n/a | u += self.type2test("eggs") |
---|
298 | n/a | self.assertEqual(u, self.type2test("spameggs")) |
---|
299 | n/a | |
---|
300 | n/a | def test_imul(self): |
---|
301 | n/a | u = self.type2test([0, 1]) |
---|
302 | n/a | u *= 3 |
---|
303 | n/a | self.assertEqual(u, self.type2test([0, 1, 0, 1, 0, 1])) |
---|
304 | n/a | |
---|
305 | n/a | def test_getitemoverwriteiter(self): |
---|
306 | n/a | # Verify that __getitem__ overrides are not recognized by __iter__ |
---|
307 | n/a | class T(self.type2test): |
---|
308 | n/a | def __getitem__(self, key): |
---|
309 | n/a | return str(key) + '!!!' |
---|
310 | n/a | self.assertEqual(next(iter(T((1,2)))), 1) |
---|
311 | n/a | |
---|
312 | n/a | def test_repeat(self): |
---|
313 | n/a | for m in range(4): |
---|
314 | n/a | s = tuple(range(m)) |
---|
315 | n/a | for n in range(-3, 5): |
---|
316 | n/a | self.assertEqual(self.type2test(s*n), self.type2test(s)*n) |
---|
317 | n/a | self.assertEqual(self.type2test(s)*(-4), self.type2test([])) |
---|
318 | n/a | self.assertEqual(id(s), id(s*1)) |
---|
319 | n/a | |
---|
320 | n/a | def test_bigrepeat(self): |
---|
321 | n/a | if sys.maxsize <= 2147483647: |
---|
322 | n/a | x = self.type2test([0]) |
---|
323 | n/a | x *= 2**16 |
---|
324 | n/a | self.assertRaises(MemoryError, x.__mul__, 2**16) |
---|
325 | n/a | if hasattr(x, '__imul__'): |
---|
326 | n/a | self.assertRaises(MemoryError, x.__imul__, 2**16) |
---|
327 | n/a | |
---|
328 | n/a | def test_subscript(self): |
---|
329 | n/a | a = self.type2test([10, 11]) |
---|
330 | n/a | self.assertEqual(a.__getitem__(0), 10) |
---|
331 | n/a | self.assertEqual(a.__getitem__(1), 11) |
---|
332 | n/a | self.assertEqual(a.__getitem__(-2), 10) |
---|
333 | n/a | self.assertEqual(a.__getitem__(-1), 11) |
---|
334 | n/a | self.assertRaises(IndexError, a.__getitem__, -3) |
---|
335 | n/a | self.assertRaises(IndexError, a.__getitem__, 3) |
---|
336 | n/a | self.assertEqual(a.__getitem__(slice(0,1)), self.type2test([10])) |
---|
337 | n/a | self.assertEqual(a.__getitem__(slice(1,2)), self.type2test([11])) |
---|
338 | n/a | self.assertEqual(a.__getitem__(slice(0,2)), self.type2test([10, 11])) |
---|
339 | n/a | self.assertEqual(a.__getitem__(slice(0,3)), self.type2test([10, 11])) |
---|
340 | n/a | self.assertEqual(a.__getitem__(slice(3,5)), self.type2test([])) |
---|
341 | n/a | self.assertRaises(ValueError, a.__getitem__, slice(0, 10, 0)) |
---|
342 | n/a | self.assertRaises(TypeError, a.__getitem__, 'x') |
---|
343 | n/a | |
---|
344 | n/a | def test_count(self): |
---|
345 | n/a | a = self.type2test([0, 1, 2])*3 |
---|
346 | n/a | self.assertEqual(a.count(0), 3) |
---|
347 | n/a | self.assertEqual(a.count(1), 3) |
---|
348 | n/a | self.assertEqual(a.count(3), 0) |
---|
349 | n/a | |
---|
350 | n/a | self.assertRaises(TypeError, a.count) |
---|
351 | n/a | |
---|
352 | n/a | class BadExc(Exception): |
---|
353 | n/a | pass |
---|
354 | n/a | |
---|
355 | n/a | class BadCmp: |
---|
356 | n/a | def __eq__(self, other): |
---|
357 | n/a | if other == 2: |
---|
358 | n/a | raise BadExc() |
---|
359 | n/a | return False |
---|
360 | n/a | |
---|
361 | n/a | self.assertRaises(BadExc, a.count, BadCmp()) |
---|
362 | n/a | |
---|
363 | n/a | def test_index(self): |
---|
364 | n/a | u = self.type2test([0, 1]) |
---|
365 | n/a | self.assertEqual(u.index(0), 0) |
---|
366 | n/a | self.assertEqual(u.index(1), 1) |
---|
367 | n/a | self.assertRaises(ValueError, u.index, 2) |
---|
368 | n/a | |
---|
369 | n/a | u = self.type2test([-2, -1, 0, 0, 1, 2]) |
---|
370 | n/a | self.assertEqual(u.count(0), 2) |
---|
371 | n/a | self.assertEqual(u.index(0), 2) |
---|
372 | n/a | self.assertEqual(u.index(0, 2), 2) |
---|
373 | n/a | self.assertEqual(u.index(-2, -10), 0) |
---|
374 | n/a | self.assertEqual(u.index(0, 3), 3) |
---|
375 | n/a | self.assertEqual(u.index(0, 3, 4), 3) |
---|
376 | n/a | self.assertRaises(ValueError, u.index, 2, 0, -10) |
---|
377 | n/a | |
---|
378 | n/a | self.assertRaises(TypeError, u.index) |
---|
379 | n/a | |
---|
380 | n/a | class BadExc(Exception): |
---|
381 | n/a | pass |
---|
382 | n/a | |
---|
383 | n/a | class BadCmp: |
---|
384 | n/a | def __eq__(self, other): |
---|
385 | n/a | if other == 2: |
---|
386 | n/a | raise BadExc() |
---|
387 | n/a | return False |
---|
388 | n/a | |
---|
389 | n/a | a = self.type2test([0, 1, 2, 3]) |
---|
390 | n/a | self.assertRaises(BadExc, a.index, BadCmp()) |
---|
391 | n/a | |
---|
392 | n/a | a = self.type2test([-2, -1, 0, 0, 1, 2]) |
---|
393 | n/a | self.assertEqual(a.index(0), 2) |
---|
394 | n/a | self.assertEqual(a.index(0, 2), 2) |
---|
395 | n/a | self.assertEqual(a.index(0, -4), 2) |
---|
396 | n/a | self.assertEqual(a.index(-2, -10), 0) |
---|
397 | n/a | self.assertEqual(a.index(0, 3), 3) |
---|
398 | n/a | self.assertEqual(a.index(0, -3), 3) |
---|
399 | n/a | self.assertEqual(a.index(0, 3, 4), 3) |
---|
400 | n/a | self.assertEqual(a.index(0, -3, -2), 3) |
---|
401 | n/a | self.assertEqual(a.index(0, -4*sys.maxsize, 4*sys.maxsize), 2) |
---|
402 | n/a | self.assertRaises(ValueError, a.index, 0, 4*sys.maxsize,-4*sys.maxsize) |
---|
403 | n/a | self.assertRaises(ValueError, a.index, 2, 0, -10) |
---|
404 | n/a | |
---|
405 | n/a | def test_pickle(self): |
---|
406 | n/a | lst = self.type2test([4, 5, 6, 7]) |
---|
407 | n/a | for proto in range(pickle.HIGHEST_PROTOCOL + 1): |
---|
408 | n/a | lst2 = pickle.loads(pickle.dumps(lst, proto)) |
---|
409 | n/a | self.assertEqual(lst2, lst) |
---|
410 | n/a | self.assertNotEqual(id(lst2), id(lst)) |
---|
411 | n/a | |
---|
412 | n/a | def test_free_after_iterating(self): |
---|
413 | n/a | support.check_free_after_iterating(self, iter, self.type2test) |
---|
414 | n/a | support.check_free_after_iterating(self, reversed, self.type2test) |
---|