Skip to content

Commit 49597bc

Browse files
committed
Add tests for islice
1 parent 2c061c0 commit 49597bc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

extra_tests/snippets/stdlib_itertools.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,28 +260,39 @@ def underten(x):
260260
def assert_matches_seq(it, seq):
261261
assert list(it) == list(seq)
262262

263+
def test_islice_pickle(it):
264+
for p in range(pickle.HIGHEST_PROTOCOL + 1):
265+
it == pickle.loads(pickle.dumps(it, p))
266+
263267
i = itertools.islice
264268

265269
it = i([1, 2, 3, 4, 5], 3)
266270
assert_matches_seq(it, [1, 2, 3])
271+
test_islice_pickle(it)
267272

268273
it = i([0.5, 1, 1.5, 2, 2.5, 3, 4, 5], 1, 6, 2)
269274
assert_matches_seq(it, [1, 2, 3])
275+
test_islice_pickle(it)
270276

271277
it = i([1, 2], None)
272278
assert_matches_seq(it, [1, 2])
279+
test_islice_pickle(it)
273280

274281
it = i([1, 2, 3], None, None, None)
275282
assert_matches_seq(it, [1, 2, 3])
283+
test_islice_pickle(it)
276284

277285
it = i([1, 2, 3], 1, None, None)
278286
assert_matches_seq(it, [2, 3])
287+
test_islice_pickle(it)
279288

280289
it = i([1, 2, 3], None, 2, None)
281290
assert_matches_seq(it, [1, 2])
291+
test_islice_pickle(it)
282292

283293
it = i([1, 2, 3], None, None, 3)
284294
assert_matches_seq(it, [1])
295+
test_islice_pickle(it)
285296

286297
# itertools.filterfalse
287298
it = itertools.filterfalse(lambda x: x%2, range(10))

0 commit comments

Comments
 (0)