Skip to content

Commit a1ff3c1

Browse files
committed
test: itertools.batched fix for older versions
1 parent 201b485 commit a1ff3c1

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

test/unit/features/conftest.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from threading import Timer
2929

30-
import itertools
30+
from itertools import islice
3131

3232
from requests import codes
3333
from requests.exceptions import ConnectionError
@@ -337,8 +337,18 @@ def __init__(self,
337337
self.plus_one_paging: bool = self.pager_type in PaginationMockSupport.key_pagers
338338
self.expected_pages: list[list] = []
339339

340+
# for compatibility with python <= 3.12
341+
def batched(self, iterable, n):
342+
"""Batch data into tuples of length n. The last batch may be shorter."""
343+
it = iter(iterable)
344+
while True:
345+
batch = tuple(islice(it, n))
346+
if not batch:
347+
break
348+
yield batch
349+
340350
def generator(self):
341-
for page in itertools.batched(range(0, self.total_items), self.page_size):
351+
for page in self.batched(range(0, self.total_items), self.page_size):
342352
rows = [PaginationMockSupport.make_row(self.pager_type, i) for i in page]
343353
if self.plus_one_paging:
344354
# Add an n+1 row for key based paging if more pages

0 commit comments

Comments
 (0)