diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2022-12-08 15:08:16 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-08 15:08:16 -0600 |
commit | 35cc0ea736a323119157117d93e5d68d8247e89f (patch) | |
tree | 4609a468592c62bf37b83a5e308331d00362b531 /Lib/test | |
parent | 41d4ac9da348ca33056e271d71588b2dc3a6d48d (diff) | |
download | cpython-35cc0ea736a323119157117d93e5d68d8247e89f.tar.gz cpython-35cc0ea736a323119157117d93e5d68d8247e89f.zip |
GH-98363: Have batched() return tuples (GH-100118)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_itertools.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 5f5bcbc7cfb..b447b6cbab9 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -161,11 +161,11 @@ class TestBasicOps(unittest.TestCase): def test_batched(self): self.assertEqual(list(batched('ABCDEFG', 3)), - [['A', 'B', 'C'], ['D', 'E', 'F'], ['G']]) + [('A', 'B', 'C'), ('D', 'E', 'F'), ('G',)]) self.assertEqual(list(batched('ABCDEFG', 2)), - [['A', 'B'], ['C', 'D'], ['E', 'F'], ['G']]) + [('A', 'B'), ('C', 'D'), ('E', 'F'), ('G',)]) self.assertEqual(list(batched('ABCDEFG', 1)), - [['A'], ['B'], ['C'], ['D'], ['E'], ['F'], ['G']]) + [('A',), ('B',), ('C',), ('D',), ('E',), ('F',), ('G',)]) with self.assertRaises(TypeError): # Too few arguments list(batched('ABCDEFG')) @@ -188,8 +188,8 @@ class TestBasicOps(unittest.TestCase): with self.subTest(s=s, n=n, batches=batches): # Order is preserved and no data is lost self.assertEqual(''.join(chain(*batches)), s) - # Each batch is an exact list - self.assertTrue(all(type(batch) is list for batch in batches)) + # Each batch is an exact tuple + self.assertTrue(all(type(batch) is tuple for batch in batches)) # All but the last batch is of size n if batches: last_batch = batches.pop() @@ -1809,12 +1809,12 @@ class TestPurePythonRoughEquivalents(unittest.TestCase): def test_batched_recipe(self): def batched_recipe(iterable, n): - "Batch data into lists of length n. The last batch may be shorter." + "Batch data into tuples of length n. The last batch may be shorter." # batched('ABCDEFG', 3) --> ABC DEF G if n < 1: raise ValueError('n must be at least one') it = iter(iterable) - while (batch := list(islice(it, n))): + while (batch := tuple(islice(it, n))): yield batch for iterable, n in product( @@ -2087,7 +2087,7 @@ class TestVariousIteratorArgs(unittest.TestCase): def test_batched(self): s = 'abcde' - r = [['a', 'b'], ['c', 'd'], ['e']] + r = [('a', 'b'), ('c', 'd'), ('e',)] n = 2 for g in (G, I, Ig, L, R): with self.subTest(g=g): |