Skip to content

Commit fdf4b3d

Browse files
committed
Make tests work in CI
1 parent ebdf822 commit fdf4b3d

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

src/apify_client/clients/base/resource_collection_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def _list(self, **kwargs: Any) -> ListPage:
5252

5353
return ListPage(parse_date_fields(pluck_data(response.json())))
5454

55-
5655
def _list_iterable(self, **kwargs: Any) -> IterableListPage[T]:
5756
"""Return object can be awaited or iterated over."""
5857
chunk_size = kwargs.pop('chunk_size', None)
@@ -192,7 +191,8 @@ class ListPageProtocol(Protocol[T], Iterable[T]):
192191
desc: bool
193192
"""Whether the listing is descending or not"""
194193

195-
class IterableListPage(Generic[T], ListPage[T]):
194+
195+
class IterableListPage(ListPage[T], Generic[T]):
196196
"""Can be called to get ListPage with items or iterated over to get individual items."""
197197

198198
def __init__(self, list_page: ListPage[T], iterator: Iterator[T]) -> None:
@@ -208,9 +208,11 @@ def __iter__(self) -> Iterator[T]:
208208
"""Return an iterator over the items from API, possibly doing multiple API calls."""
209209
return self._iterator
210210

211+
211212
class ListPageProtocolAsync(Protocol[T], AsyncIterable[T], Awaitable[ListPage[T]]):
212213
"""Protocol for an object that can be both awaited and asynchronously iterated over."""
213214

215+
214216
class IterableListPageAsync(Generic[T]):
215217
"""Can be awaited to get ListPage with items or asynchronously iterated over to get individual items."""
216218

tests/integration/test_client_pagination.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/unit/test_client_pagination.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def mocked_api_pagination_logic(*_: Any, **kwargs: Any) -> dict:
113113
@dataclasses.dataclass
114114
class TestCase:
115115
"""Class representing a single test case for pagination tests."""
116+
116117
id: str
117118
inputs: dict
118119
expected_items: list[dict[str, int]]
@@ -154,7 +155,7 @@ def supports(self, client: BaseClient | BaseClientAsync) -> bool:
154155

155156
ALL_CLIENTS = COLLECTION_CLIENTS | NO_OPTIONS_CLIENTS | STORAGE_CLIENTS
156157

157-
TEST_CASES = {
158+
TEST_CASES = (
158159
TestCase('No options', {}, create_items(0, 2500), ALL_CLIENTS),
159160
TestCase('Limit', {'limit': 1100}, create_items(0, 1100), ALL_CLIENTS - NO_OPTIONS_CLIENTS),
160161
TestCase('Out of range limit', {'limit': 3000}, create_items(0, 2500), ALL_CLIENTS - NO_OPTIONS_CLIENTS),
@@ -183,7 +184,7 @@ def supports(self, client: BaseClient | BaseClientAsync) -> bool:
183184
),
184185
TestCase('Exclusive start key', {'exclusive_start_key': 1000}, create_items(1001, 2500), {'KeyValueStoreClient'}),
185186
TestCase('Exclusive start id', {'exclusive_start_id': 1000}, create_items(1001, 2500), {'RequestQueueClient'}),
186-
}
187+
)
187188

188189

189190
def generate_test_params(
@@ -196,11 +197,13 @@ def generate_test_params(
196197

197198
client = ApifyClientAsync(token='') if async_clients else ApifyClient(token='')
198199

199-
clients: set[BaseClient | BaseClientAsync]
200+
# This is tuple instead of set because pytest-xdist
201+
# https://pytest-xdist.readthedocs.io/en/stable/known-limitations.html#order-and-amount-of-test-must-be-consistent
202+
clients: tuple[BaseClient | BaseClientAsync, ...]
200203

201204
match client_set:
202205
case 'collection':
203-
clients = {
206+
clients = (
204207
client.actors(),
205208
client.schedules(),
206209
client.tasks(),
@@ -214,13 +217,13 @@ def generate_test_params(
214217
client.actor('some-id').runs(),
215218
client.actor('some-id').versions(),
216219
client.actor('some-id').version('some-version').env_vars(),
217-
}
220+
)
218221
case 'kvs':
219-
clients = {client.key_value_store('some-id')}
222+
clients = (client.key_value_store('some-id'),)
220223
case 'rq':
221-
clients = {client.request_queue('some-id')}
224+
clients = (client.request_queue('some-id'),)
222225
case 'dataset':
223-
clients = {client.dataset('some-id')}
226+
clients = (client.dataset('some-id'),)
224227
case _:
225228
raise ValueError(f'Unknown client set: {client_set}')
226229

0 commit comments

Comments
 (0)