Skip to content

Commit bad0ce4

Browse files
committed
Rework the async test variant to give better test names
We now show `default` instead of `false`
1 parent 82e40ce commit bad0ce4

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

tests/test_use.py

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
from enum import Enum
34
from pathlib import Path
45

56
import httpx
@@ -8,6 +9,12 @@
89

910
import replicate
1011

12+
13+
class ClientMode(str, Enum):
14+
DEFAULT = "default"
15+
ASYNC = "async"
16+
17+
1118
# Allow use() to be called in test context
1219
os.environ["REPLICATE_ALWAYS_ALLOW_USE"] = "1"
1320

@@ -240,9 +247,9 @@ def mock_prediction_endpoints(
240247

241248

242249
@pytest.mark.asyncio
243-
@pytest.mark.parametrize("use_async_client", [False])
250+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
244251
@respx.mock
245-
async def test_use(use_async_client):
252+
async def test_use(client_mode):
246253
mock_model_endpoints()
247254
mock_prediction_endpoints()
248255

@@ -257,9 +264,9 @@ async def test_use(use_async_client):
257264

258265

259266
@pytest.mark.asyncio
260-
@pytest.mark.parametrize("use_async_client", [False])
267+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
261268
@respx.mock
262-
async def test_use_with_version_identifier(use_async_client):
269+
async def test_use_with_version_identifier(client_mode):
263270
mock_model_endpoints()
264271
mock_prediction_endpoints()
265272

@@ -274,9 +281,9 @@ async def test_use_with_version_identifier(use_async_client):
274281

275282

276283
@pytest.mark.asyncio
277-
@pytest.mark.parametrize("use_async_client", [False])
284+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
278285
@respx.mock
279-
async def test_use_versionless_empty_versions_list(use_async_client):
286+
async def test_use_versionless_empty_versions_list(client_mode):
280287
mock_model_endpoints(has_no_versions=True, uses_versionless_api=True)
281288
mock_prediction_endpoints(uses_versionless_api=True)
282289

@@ -291,9 +298,9 @@ async def test_use_versionless_empty_versions_list(use_async_client):
291298

292299

293300
@pytest.mark.asyncio
294-
@pytest.mark.parametrize("use_async_client", [False])
301+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
295302
@respx.mock
296-
async def test_use_versionless_404_versions_list(use_async_client):
303+
async def test_use_versionless_404_versions_list(client_mode):
297304
mock_model_endpoints(uses_versionless_api=True)
298305
mock_prediction_endpoints(uses_versionless_api=True)
299306

@@ -308,9 +315,9 @@ async def test_use_versionless_404_versions_list(use_async_client):
308315

309316

310317
@pytest.mark.asyncio
311-
@pytest.mark.parametrize("use_async_client", [False])
318+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
312319
@respx.mock
313-
async def test_use_function_create_method(use_async_client):
320+
async def test_use_function_create_method(client_mode):
314321
mock_model_endpoints()
315322
mock_prediction_endpoints()
316323

@@ -328,9 +335,9 @@ async def test_use_function_create_method(use_async_client):
328335

329336

330337
@pytest.mark.asyncio
331-
@pytest.mark.parametrize("use_async_client", [False])
338+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
332339
@respx.mock
333-
async def test_use_concatenate_iterator_output(use_async_client):
340+
async def test_use_concatenate_iterator_output(client_mode):
334341
mock_model_endpoints(
335342
version_overrides={
336343
"openapi_schema": {
@@ -406,9 +413,9 @@ def capture_request(request):
406413

407414

408415
@pytest.mark.asyncio
409-
@pytest.mark.parametrize("use_async_client", [False])
416+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
410417
@respx.mock
411-
async def test_use_list_of_strings_output(use_async_client):
418+
async def test_use_list_of_strings_output(client_mode):
412419
mock_model_endpoints(
413420
version_overrides={
414421
"openapi_schema": {
@@ -437,9 +444,9 @@ async def test_use_list_of_strings_output(use_async_client):
437444

438445

439446
@pytest.mark.asyncio
440-
@pytest.mark.parametrize("use_async_client", [False])
447+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
441448
@respx.mock
442-
async def test_use_iterator_of_strings_output(use_async_client):
449+
async def test_use_iterator_of_strings_output(client_mode):
443450
mock_model_endpoints(
444451
version_overrides={
445452
"openapi_schema": {
@@ -474,9 +481,9 @@ async def test_use_iterator_of_strings_output(use_async_client):
474481

475482

476483
@pytest.mark.asyncio
477-
@pytest.mark.parametrize("use_async_client", [False])
484+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
478485
@respx.mock
479-
async def test_use_path_output(use_async_client):
486+
async def test_use_path_output(client_mode):
480487
mock_model_endpoints(
481488
version_overrides={
482489
"openapi_schema": {
@@ -507,9 +514,9 @@ async def test_use_path_output(use_async_client):
507514

508515

509516
@pytest.mark.asyncio
510-
@pytest.mark.parametrize("use_async_client", [False])
517+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
511518
@respx.mock
512-
async def test_use_list_of_paths_output(use_async_client):
519+
async def test_use_list_of_paths_output(client_mode):
513520
mock_model_endpoints(
514521
version_overrides={
515522
"openapi_schema": {
@@ -555,9 +562,9 @@ async def test_use_list_of_paths_output(use_async_client):
555562

556563

557564
@pytest.mark.asyncio
558-
@pytest.mark.parametrize("use_async_client", [False])
565+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
559566
@respx.mock
560-
async def test_use_iterator_of_paths_output(use_async_client):
567+
async def test_use_iterator_of_paths_output(client_mode):
561568
mock_model_endpoints(
562569
version_overrides={
563570
"openapi_schema": {
@@ -681,9 +688,9 @@ def __init__(self, target) -> None:
681688

682689

683690
@pytest.mark.asyncio
684-
@pytest.mark.parametrize("use_async_client", [False])
691+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
685692
@respx.mock
686-
async def test_use_pathproxy_input_conversion(use_async_client):
693+
async def test_use_pathproxy_input_conversion(client_mode):
687694
"""Test that PathProxy instances are converted to URLs when passed to create()."""
688695
mock_model_endpoints()
689696

@@ -740,9 +747,9 @@ def capture_request(request):
740747

741748

742749
@pytest.mark.asyncio
743-
@pytest.mark.parametrize("use_async_client", [False])
750+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
744751
@respx.mock
745-
async def test_use_function_logs_method(use_async_client):
752+
async def test_use_function_logs_method(client_mode):
746753
mock_model_endpoints()
747754
mock_prediction_endpoints()
748755

@@ -758,9 +765,9 @@ async def test_use_function_logs_method(use_async_client):
758765

759766

760767
@pytest.mark.asyncio
761-
@pytest.mark.parametrize("use_async_client", [False])
768+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
762769
@respx.mock
763-
async def test_use_function_logs_method_polling(use_async_client):
770+
async def test_use_function_logs_method_polling(client_mode):
764771
mock_model_endpoints()
765772

766773
# Mock prediction endpoints with updated logs on polling
@@ -815,9 +822,9 @@ async def test_use_function_logs_method_polling(use_async_client):
815822

816823

817824
@pytest.mark.asyncio
818-
@pytest.mark.parametrize("use_async_client", [False])
825+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
819826
@respx.mock
820-
async def test_use_object_output_with_file_properties(use_async_client):
827+
async def test_use_object_output_with_file_properties(client_mode):
821828
mock_model_endpoints(
822829
version_overrides={
823830
"openapi_schema": {
@@ -869,9 +876,9 @@ async def test_use_object_output_with_file_properties(use_async_client):
869876

870877

871878
@pytest.mark.asyncio
872-
@pytest.mark.parametrize("use_async_client", [False])
879+
@pytest.mark.parametrize("client_mode", [ClientMode.DEFAULT])
873880
@respx.mock
874-
async def test_use_object_output_with_file_list_property(use_async_client):
881+
async def test_use_object_output_with_file_list_property(client_mode):
875882
mock_model_endpoints(
876883
version_overrides={
877884
"openapi_schema": {

0 commit comments

Comments
 (0)