Skip to content

Commit c3f55c7

Browse files
committed
test: itertools.batched fix for older versions
1 parent abc0f66 commit c3f55c7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/unit/features/conftest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from threading import Timer
2929

3030
import itertools
31+
from itertools import islice
3132

3233
from requests import codes
3334
from requests.exceptions import ConnectionError
@@ -337,8 +338,18 @@ def __init__(self,
337338
self.plus_one_paging: bool = self.pager_type in PaginationMockSupport.key_pagers
338339
self.expected_pages: list[list] = []
339340

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

0 commit comments

Comments
 (0)