11from datetime import datetime , timedelta , timezone
2- from typing import Any , Iterable , List
2+ from typing import Any , Iterable
33
44import pytest
55from freezegun import freeze_time
66
77from dstack ._internal .utils .common import (
8+ batched ,
89 concat_url_path ,
910 format_duration_multiunit ,
1011 local_time ,
1112 make_proxy_url ,
1213 parse_memory ,
1314 pretty_date ,
1415 sizeof_fmt ,
15- split_chunks ,
1616)
1717
1818
@@ -138,9 +138,9 @@ def test_parses_memory(self, memory, as_units, expected):
138138 assert parse_memory (memory , as_untis = as_units ) == expected
139139
140140
141- class TestSplitChunks :
141+ class TestBatched :
142142 @pytest .mark .parametrize (
143- ("iterable" , "chunk_size " , "expected_chunks " ),
143+ ("iterable" , "n " , "expected_batches " ),
144144 [
145145 ([1 , 2 , 3 , 4 ], 2 , [[1 , 2 ], [3 , 4 ]]),
146146 ([1 , 2 , 3 ], 2 , [[1 , 2 ], [3 ]]),
@@ -151,15 +151,15 @@ class TestSplitChunks:
151151 ((x for x in range (5 )), 3 , [[0 , 1 , 2 ], [3 , 4 ]]),
152152 ],
153153 )
154- def test_split_chunks (
155- self , iterable : Iterable [Any ], chunk_size : int , expected_chunks : List [ List [Any ]]
154+ def test_batched (
155+ self , iterable : Iterable [Any ], n : int , expected_batches : list [ list [Any ]]
156156 ) -> None :
157- assert list (split_chunks (iterable , chunk_size )) == expected_chunks
157+ assert list (batched (iterable , n )) == expected_batches
158158
159- @pytest .mark .parametrize ("chunk_size " , [0 , - 1 ])
160- def test_raises_on_invalid_chunk_size (self , chunk_size : int ) -> None :
159+ @pytest .mark .parametrize ("n " , [0 , - 1 ])
160+ def test_raises_on_invalid_n (self , n : int ) -> None :
161161 with pytest .raises (ValueError ):
162- list (split_chunks ([1 , 2 , 3 ], chunk_size ))
162+ list (batched ([1 , 2 , 3 ], n ))
163163
164164
165165@pytest .mark .parametrize (
0 commit comments