diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-24 10:36:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-24 10:36:11 (GMT) |
commit | c247caf33f6e6000d828db4762d1cb12edf3cd57 (patch) | |
tree | 85caedaba2394380c428839bda687f23dd853e43 /Lib | |
parent | 4facdf523aa6967487a9425f124da9661b59fd43 (diff) | |
download | cpython-c247caf33f6e6000d828db4762d1cb12edf3cd57.zip cpython-c247caf33f6e6000d828db4762d1cb12edf3cd57.tar.gz cpython-c247caf33f6e6000d828db4762d1cb12edf3cd57.tar.bz2 |
bpo-30346: An iterator produced by the itertools.groupby() iterator (#1569)
now becames exhausted after advancing the groupby iterator.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_itertools.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 50cf148..8353e68 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -751,6 +751,26 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(set(keys), expectedkeys) self.assertEqual(len(keys), len(expectedkeys)) + # Check case where inner iterator is used after advancing the groupby + # iterator + s = list(zip('AABBBAAAA', range(9))) + it = groupby(s, testR) + _, g1 = next(it) + _, g2 = next(it) + _, g3 = next(it) + self.assertEqual(list(g1), []) + self.assertEqual(list(g2), []) + self.assertEqual(next(g3), ('A', 5)) + list(it) # exhaust the groupby iterator + self.assertEqual(list(g3), []) + + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + it = groupby(s, testR) + _, g = next(it) + next(it) + next(it) + self.assertEqual(list(pickle.loads(pickle.dumps(g, proto))), []) + # Exercise pipes and filters style s = 'abracadabra' # sort s | uniq |