Skip to content

Commit cc510cd

Browse files
Use keyword-only parameters in tests (#2986)
Enforce keyword-only arguments in test functions that accept multiple parameters, improving call-site clarity.
1 parent 88b2a8e commit cc510cd

16 files changed

Lines changed: 126 additions & 11 deletions

ci/test_custom_linters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def test_ci_patterns_valid(request: pytest.FixtureRequest) -> None:
8383

8484

8585
def test_tests_collected_once(
86+
*,
8687
capsys: pytest.CaptureFixture[str],
8788
request: pytest.FixtureRequest,
8889
) -> None:

tests/mock_vws/test_add_target.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class TestContentTypes:
103103
],
104104
)
105105
def test_content_types(
106+
*,
106107
vws_client: VWS,
107108
image_file_failed_state: io.BytesIO,
108109
content_type: str,
@@ -129,6 +130,7 @@ def test_content_types(
129130

130131
@staticmethod
131132
def test_empty_content_type(
133+
*,
132134
vws_client: VWS,
133135
image_file_failed_state: io.BytesIO,
134136
) -> None:
@@ -174,6 +176,7 @@ class TestMissingData:
174176
argvalues=["name", "width", "image"],
175177
)
176178
def test_missing_data(
179+
*,
177180
vws_client: VWS,
178181
image_file_failed_state: io.BytesIO,
179182
data_to_remove: str,
@@ -212,6 +215,7 @@ class TestWidth:
212215
ids=["Negative", "Wrong Type", "None", "Zero"],
213216
)
214217
def test_width_invalid(
218+
*,
215219
vws_client: VWS,
216220
image_file_failed_state: io.BytesIO,
217221
width: int | str | None,
@@ -239,6 +243,7 @@ def test_width_invalid(
239243

240244
@staticmethod
241245
def test_width_valid(
246+
*,
242247
vws_client: VWS,
243248
image_file_failed_state: io.BytesIO,
244249
) -> None:
@@ -273,6 +278,7 @@ class TestTargetName:
273278
ids=["Short name", "Max char value", "Long name"],
274279
)
275280
def test_name_valid(
281+
*,
276282
name: str,
277283
image_file_failed_state: io.BytesIO,
278284
vws_client: VWS,
@@ -310,6 +316,7 @@ def test_name_valid(
310316
],
311317
)
312318
def test_name_invalid(
319+
*,
313320
name: str | int | None,
314321
image_file_failed_state: io.BytesIO,
315322
status_code: int,
@@ -349,6 +356,7 @@ def test_name_invalid(
349356

350357
@staticmethod
351358
def test_existing_target_name(
359+
*,
352360
image_file_failed_state: io.BytesIO,
353361
vws_client: VWS,
354362
) -> None:
@@ -378,6 +386,7 @@ def test_existing_target_name(
378386

379387
@staticmethod
380388
def test_deleted_existing_target_name(
389+
*,
381390
image_file_failed_state: io.BytesIO,
382391
vws_client: VWS,
383392
) -> None:
@@ -411,6 +420,7 @@ class TestImage:
411420

412421
@staticmethod
413422
def test_image_valid(
423+
*,
414424
vws_client: VWS,
415425
image_files_failed_state: io.BytesIO,
416426
) -> None:
@@ -428,6 +438,7 @@ def test_image_valid(
428438

429439
@staticmethod
430440
def test_bad_image_format_or_color_space(
441+
*,
431442
bad_image_file: io.BytesIO,
432443
vws_client: VWS,
433444
) -> None:
@@ -454,6 +465,7 @@ def test_bad_image_format_or_color_space(
454465

455466
@staticmethod
456467
def test_corrupted(
468+
*,
457469
corrupted_image_file: io.BytesIO,
458470
vws_client: VWS,
459471
) -> None:
@@ -543,6 +555,7 @@ def test_image_file_size_too_large(vws_client: VWS) -> None:
543555

544556
@staticmethod
545557
def test_not_base64_encoded_processable(
558+
*,
546559
vws_client: VWS,
547560
not_base64_encoded_processable: str,
548561
) -> None:
@@ -570,6 +583,7 @@ def test_not_base64_encoded_processable(
570583

571584
@staticmethod
572585
def test_not_base64_encoded_not_processable(
586+
*,
573587
vws_client: VWS,
574588
not_base64_encoded_not_processable: str,
575589
) -> None:
@@ -622,6 +636,7 @@ def test_not_image(vws_client: VWS) -> None:
622636
argvalues=[1, None],
623637
)
624638
def test_invalid_type(
639+
*,
625640
invalid_type_image: int | None,
626641
vws_client: VWS,
627642
) -> None:
@@ -681,6 +696,7 @@ def test_valid(
681696

682697
@staticmethod
683698
def test_invalid(
699+
*,
684700
image_file_failed_state: io.BytesIO,
685701
vws_client: VWS,
686702
) -> None:
@@ -717,6 +733,7 @@ def test_invalid(
717733

718734
@staticmethod
719735
def test_not_set(
736+
*,
720737
vws_client: VWS,
721738
image_file_failed_state: io.BytesIO,
722739
) -> None:
@@ -740,6 +757,7 @@ def test_not_set(
740757

741758
@staticmethod
742759
def test_set_to_none(
760+
*,
743761
vws_client: VWS,
744762
image_file_failed_state: io.BytesIO,
745763
) -> None:
@@ -773,6 +791,7 @@ class TestUnexpectedData:
773791

774792
@staticmethod
775793
def test_invalid_extra_data(
794+
*,
776795
vws_client: VWS,
777796
image_file_failed_state: io.BytesIO,
778797
) -> None:
@@ -816,6 +835,7 @@ class TestApplicationMetadata:
816835
ids=["Short", "Max length"],
817836
)
818837
def test_base64_encoded(
838+
*,
819839
image_file_failed_state: io.BytesIO,
820840
metadata: bytes,
821841
vws_client: VWS,
@@ -835,6 +855,7 @@ def test_base64_encoded(
835855

836856
@staticmethod
837857
def test_null(
858+
*,
838859
vws_client: VWS,
839860
image_file_failed_state: io.BytesIO,
840861
) -> None:
@@ -860,6 +881,7 @@ def test_null(
860881

861882
@staticmethod
862883
def test_invalid_type(
884+
*,
863885
vws_client: VWS,
864886
image_file_failed_state: io.BytesIO,
865887
) -> None:
@@ -890,6 +912,7 @@ def test_invalid_type(
890912

891913
@staticmethod
892914
def test_not_base64_encoded_processable(
915+
*,
893916
high_quality_image: io.BytesIO,
894917
not_base64_encoded_processable: str,
895918
vws_client: VWS,
@@ -909,6 +932,7 @@ def test_not_base64_encoded_processable(
909932

910933
@staticmethod
911934
def test_not_base64_encoded_not_processable(
935+
*,
912936
high_quality_image: io.BytesIO,
913937
not_base64_encoded_not_processable: str,
914938
vws_client: VWS,
@@ -935,6 +959,7 @@ def test_not_base64_encoded_not_processable(
935959

936960
@staticmethod
937961
def test_metadata_too_large(
962+
*,
938963
image_file_failed_state: io.BytesIO,
939964
vws_client: VWS,
940965
) -> None:
@@ -970,6 +995,7 @@ class TestInactiveProject:
970995

971996
@staticmethod
972997
def test_inactive_project(
998+
*,
973999
image_file_failed_state: io.BytesIO,
9741000
inactive_vws_client: VWS,
9751001
) -> None:

tests/mock_vws/test_authorization_header.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def test_bad_access_key_services(
265265

266266
@staticmethod
267267
def test_bad_access_key_query(
268+
*,
268269
vuforia_database: CloudDatabase,
269270
high_quality_image: io.BytesIO,
270271
) -> None:
@@ -328,6 +329,7 @@ def test_bad_secret_key_services(
328329

329330
@staticmethod
330331
def test_bad_secret_key_query(
332+
*,
331333
vuforia_database: CloudDatabase,
332334
high_quality_image: io.BytesIO,
333335
) -> None:

tests/mock_vws/test_database_summary.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class TestDatabaseSummary:
9494

9595
@staticmethod
9696
def test_success(
97+
*,
9798
vuforia_database: CloudDatabase,
9899
vws_client: VWS,
99100
) -> None:
@@ -110,7 +111,7 @@ def test_success(
110111
)
111112

112113
@staticmethod
113-
def test_active_images(vws_client: VWS, target_id: str) -> None:
114+
def test_active_images(*, vws_client: VWS, target_id: str) -> None:
114115
"""The number of images in the active state is returned."""
115116
vws_client.wait_for_target_processed(target_id=target_id)
116117

@@ -124,6 +125,7 @@ def test_active_images(vws_client: VWS, target_id: str) -> None:
124125

125126
@staticmethod
126127
def test_failed_images(
128+
*,
127129
image_file_failed_state: io.BytesIO,
128130
vws_client: VWS,
129131
) -> None:
@@ -148,6 +150,7 @@ def test_failed_images(
148150

149151
@staticmethod
150152
def test_inactive_images(
153+
*,
151154
vws_client: VWS,
152155
image_file_success_state_low_rating: io.BytesIO,
153156
) -> None:
@@ -176,6 +179,7 @@ def test_inactive_images(
176179

177180
@staticmethod
178181
def test_inactive_failed(
182+
*,
179183
image_file_failed_state: io.BytesIO,
180184
vws_client: VWS,
181185
) -> None:
@@ -200,6 +204,7 @@ def test_inactive_failed(
200204

201205
@staticmethod
202206
def test_deleted(
207+
*,
203208
image_file_failed_state: io.BytesIO,
204209
vws_client: VWS,
205210
) -> None:
@@ -289,6 +294,7 @@ class TestRecos:
289294

290295
@staticmethod
291296
def test_query_request(
297+
*,
292298
cloud_reco_client: CloudRecoService,
293299
high_quality_image: io.BytesIO,
294300
vws_client: VWS,
@@ -344,6 +350,7 @@ def test_target_request(vws_client: VWS) -> None:
344350

345351
@staticmethod
346352
def test_bad_target_request(
353+
*,
347354
high_quality_image: io.BytesIO,
348355
vws_client: VWS,
349356
) -> None:
@@ -372,6 +379,7 @@ def test_bad_target_request(
372379

373380
@staticmethod
374381
def test_query_request(
382+
*,
375383
cloud_reco_client: CloudRecoService,
376384
high_quality_image: io.BytesIO,
377385
vws_client: VWS,

tests/mock_vws/test_delete_target.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TestDelete:
1919
"""Tests for deleting targets."""
2020

2121
@staticmethod
22-
def test_no_wait(target_id: str, vws_client: VWS) -> None:
22+
def test_no_wait(*, target_id: str, vws_client: VWS) -> None:
2323
"""When attempting to delete a target immediately after creating
2424
it, a
2525
`FORBIDDEN` response is returned.
@@ -41,7 +41,7 @@ def test_no_wait(target_id: str, vws_client: VWS) -> None:
4141
)
4242

4343
@staticmethod
44-
def test_processed(target_id: str, vws_client: VWS) -> None:
44+
def test_processed(*, target_id: str, vws_client: VWS) -> None:
4545
"""When a target has finished processing, it can be deleted."""
4646
vws_client.wait_for_target_processed(target_id=target_id)
4747
vws_client.delete_target(target_id=target_id)

tests/mock_vws/test_docker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def fixture_custom_bridge_network() -> Iterator[Network]:
8888

8989
@pytest.mark.requires_docker_build
9090
def test_build_and_run(
91+
*,
9192
high_quality_image: io.BytesIO,
9293
custom_bridge_network: Network,
9394
request: pytest.FixtureRequest,

0 commit comments

Comments
 (0)