mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-113202: Add a strict option to itertools.batched() (gh-113203)
This commit is contained in:
parent
fe479fb8a9
commit
1583c40be9
5 changed files with 60 additions and 24 deletions
|
@ -187,7 +187,11 @@ class TestBasicOps(unittest.TestCase):
|
|||
[('A', 'B'), ('C', 'D'), ('E', 'F'), ('G',)])
|
||||
self.assertEqual(list(batched('ABCDEFG', 1)),
|
||||
[('A',), ('B',), ('C',), ('D',), ('E',), ('F',), ('G',)])
|
||||
self.assertEqual(list(batched('ABCDEF', 2, strict=True)),
|
||||
[('A', 'B'), ('C', 'D'), ('E', 'F')])
|
||||
|
||||
with self.assertRaises(ValueError): # Incomplete batch when strict
|
||||
list(batched('ABCDEFG', 3, strict=True))
|
||||
with self.assertRaises(TypeError): # Too few arguments
|
||||
list(batched('ABCDEFG'))
|
||||
with self.assertRaises(TypeError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue