Add tests for islice
@@ -260,28 +260,39 @@ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
def assert_matches_seq(it, seq):
assert list(it) == list(seq)
+def test_islice_pickle(it):
+ for p in range(pickle.HIGHEST_PROTOCOL + 1):
+ it == pickle.loads(pickle.dumps(it, p))
+
i = itertools.islice
it = i([1, 2, 3, 4, 5], 3)
assert_matches_seq(it, [1, 2, 3])
+test_islice_pickle(it)
it = i([0.5, 1, 1.5, 2, 2.5, 3, 4, 5], 1, 6, 2)
assert_matches_seq(it, [1, 2, 3])
+test_islice_pickle(it)
it = i([1, 2], None)
assert_matches_seq(it, [1, 2])
+test_islice_pickle(it)
it = i([1, 2, 3], None, None, None)
assert_matches_seq(it, [1, 2, 3])
+test_islice_pickle(it)
it = i([1, 2, 3], 1, None, None)
assert_matches_seq(it, [2, 3])
+test_islice_pickle(it)
it = i([1, 2, 3], None, 2, None)
assert_matches_seq(it, [1, 2])
+test_islice_pickle(it)
it = i([1, 2, 3], None, None, 3)
assert_matches_seq(it, [1])
+test_islice_pickle(it)
# itertools.filterfalse
it = itertools.filterfalse(lambda x: x%2, range(10))
