Skip to content

Commit 5c313f8

Browse files
authored
Handle ruff PT028 changes (#53235)
1 parent 5ed4e94 commit 5c313f8

File tree

3 files changed

+87
-67
lines changed

3 files changed

+87
-67
lines changed

helm-tests/tests/helm_tests/airflow_aux/test_container_lifecycle.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import jmespath
20+
import pytest
2021
from chart_utils.helm_template_generator import render_chart
2122

2223
CONTAINER_LIFECYCLE_PARAMETERS = {
@@ -37,7 +38,8 @@ class TestContainerLifecycleHooks:
3738
"""Tests container lifecycle hooks."""
3839

3940
# Test container lifecycle hooks default setting
40-
def test_check_default_setting(self, hook_type="preStop"):
41+
@pytest.mark.parametrize("hook_type", ["preStop"])
42+
def test_check_default_setting(self, hook_type):
4143
lifecycle_hook_params = CONTAINER_LIFECYCLE_PARAMETERS[hook_type]
4244
docs = render_chart(
4345
name=lifecycle_hook_params["release_name"],
@@ -74,7 +76,8 @@ def test_check_default_setting(self, hook_type="preStop"):
7476
assert jmespath.search("spec.template.spec.containers[0].lifecycle.postStart", docs[-1]) is None
7577

7678
# Test Global container lifecycle hooks for the main services
77-
def test_global_setting(self, hook_type="preStop"):
79+
@pytest.mark.parametrize("hook_type", ["preStop"])
80+
def test_global_setting(self, hook_type):
7881
lifecycle_hook_params = CONTAINER_LIFECYCLE_PARAMETERS[hook_type]
7982
docs = render_chart(
8083
name=lifecycle_hook_params["release_name"],
@@ -98,7 +101,8 @@ def test_global_setting(self, hook_type="preStop"):
98101
)
99102

100103
# Test Global container lifecycle hooks for the main services
101-
def test_global_setting_external(self, hook_type="preStop"):
104+
@pytest.mark.parametrize("hook_type", ["preStop"])
105+
def test_global_setting_external(self, hook_type):
102106
lifecycle_hook_params = CONTAINER_LIFECYCLE_PARAMETERS[hook_type]
103107
lifecycle_hooks_config = {hook_type: lifecycle_hook_params["lifecycle_templated"]}
104108
docs = render_chart(
@@ -119,7 +123,8 @@ def test_global_setting_external(self, hook_type="preStop"):
119123
)
120124

121125
# <local>.containerLifecycleWebhooks > containerLifecycleWebhooks
122-
def test_check_main_container_setting(self, hook_type="preStop"):
126+
@pytest.mark.parametrize("hook_type", ["preStop"])
127+
def test_check_main_container_setting(self, hook_type):
123128
lifecycle_hook_params = CONTAINER_LIFECYCLE_PARAMETERS[hook_type]
124129
lifecycle_hooks_config = {hook_type: lifecycle_hook_params["lifecycle_templated"]}
125130
docs = render_chart(
@@ -164,7 +169,8 @@ def test_check_main_container_setting(self, hook_type="preStop"):
164169
)
165170

166171
# Test container lifecycle hooks for metrics-explorer main container
167-
def test_metrics_explorer_container_setting(self, hook_type="preStop"):
172+
@pytest.mark.parametrize("hook_type", ["preStop"])
173+
def test_metrics_explorer_container_setting(self, hook_type):
168174
lifecycle_hook_params = CONTAINER_LIFECYCLE_PARAMETERS[hook_type]
169175
lifecycle_hooks_config = {hook_type: lifecycle_hook_params["lifecycle_templated"]}
170176
docs = render_chart(
@@ -183,7 +189,8 @@ def test_metrics_explorer_container_setting(self, hook_type="preStop"):
183189
)
184190

185191
# Test container lifecycle hooks for worker-kerberos main container
186-
def test_worker_kerberos_container_setting(self, hook_type="preStop"):
192+
@pytest.mark.parametrize("hook_type", ["preStop"])
193+
def test_worker_kerberos_container_setting(self, hook_type):
187194
lifecycle_hook_params = CONTAINER_LIFECYCLE_PARAMETERS[hook_type]
188195
lifecycle_hooks_config = {hook_type: lifecycle_hook_params["lifecycle_templated"]}
189196
docs = render_chart(
@@ -204,7 +211,8 @@ def test_worker_kerberos_container_setting(self, hook_type="preStop"):
204211
)
205212

206213
# Test container lifecycle hooks for log-groomer-sidecar main container
207-
def test_log_groomer_sidecar_container_setting(self, hook_type="preStop"):
214+
@pytest.mark.parametrize("hook_type", ["preStop"])
215+
def test_log_groomer_sidecar_container_setting(self, hook_type):
208216
lifecycle_hook_params = CONTAINER_LIFECYCLE_PARAMETERS[hook_type]
209217
lifecycle_hooks_config = {hook_type: lifecycle_hook_params["lifecycle_templated"]}
210218
docs = render_chart(
@@ -223,6 +231,3 @@ def test_log_groomer_sidecar_container_setting(self, hook_type="preStop"):
223231
assert lifecycle_hook_params["lifecycle_parsed"] == jmespath.search(
224232
f"spec.template.spec.containers[1].lifecycle.{hook_type}", doc
225233
)
226-
227-
228-
# ruff: noqa: PT028

providers/amazon/tests/unit/amazon/aws/hooks/test_eks.py

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ def test_list_clusters_returns_empty_by_default(self) -> None:
240240
assert isinstance(result, list)
241241
assert len(result) == 0
242242

243+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
243244
def test_list_clusters_returns_sorted_cluster_names(
244-
self, cluster_builder, initial_batch_size: int = BatchCountSize.SMALL
245+
self, cluster_builder, initial_batch_size: int
245246
) -> None:
246247
eks_hook, generated_test_data = cluster_builder(count=initial_batch_size)
247248
expected_result: list = sorted(generated_test_data.cluster_names)
@@ -250,18 +251,18 @@ def test_list_clusters_returns_sorted_cluster_names(
250251

251252
assert_result_matches_expected_list(result, expected_result, initial_batch_size)
252253

253-
def test_list_clusters_returns_all_results(
254-
self, cluster_builder, initial_batch_size: int = BatchCountSize.LARGE
255-
) -> None:
254+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.LARGE])
255+
def test_list_clusters_returns_all_results(self, cluster_builder, initial_batch_size: int) -> None:
256256
eks_hook, generated_test_data = cluster_builder(count=initial_batch_size)
257257
expected_result: list = sorted(generated_test_data.cluster_names)
258258

259259
result: list = eks_hook.list_clusters()
260260

261261
assert_result_matches_expected_list(result, expected_result)
262262

263+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
263264
def test_create_cluster_throws_exception_when_cluster_exists(
264-
self, cluster_builder, initial_batch_size: int = BatchCountSize.SMALL
265+
self, cluster_builder, initial_batch_size: int
265266
) -> None:
266267
eks_hook, generated_test_data = cluster_builder(count=initial_batch_size)
267268
expected_exception: type[AWSError] = ResourceInUseException
@@ -329,8 +330,9 @@ def test_create_cluster_saves_provided_parameters(self, cluster_builder) -> None
329330
for key, expected_value in generated_test_data.attributes_to_test:
330331
assert generated_test_data.cluster_describe_output[key] == expected_value
331332

333+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
332334
def test_describe_cluster_throws_exception_when_cluster_not_found(
333-
self, cluster_builder, initial_batch_size: int = BatchCountSize.SMALL
335+
self, cluster_builder, initial_batch_size: int
334336
) -> None:
335337
eks_hook, generated_test_data = cluster_builder(count=initial_batch_size)
336338
expected_exception: type[AWSError] = ResourceNotFoundException
@@ -347,9 +349,8 @@ def test_describe_cluster_throws_exception_when_cluster_not_found(
347349
raised_exception=raised_exception,
348350
)
349351

350-
def test_delete_cluster_returns_deleted_cluster(
351-
self, cluster_builder, initial_batch_size: int = BatchCountSize.SMALL
352-
) -> None:
352+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
353+
def test_delete_cluster_returns_deleted_cluster(self, cluster_builder, initial_batch_size: int) -> None:
353354
eks_hook, generated_test_data = cluster_builder(count=initial_batch_size, minimal=False)
354355

355356
result: dict = eks_hook.delete_cluster(name=generated_test_data.existing_cluster_name)[
@@ -359,9 +360,8 @@ def test_delete_cluster_returns_deleted_cluster(
359360
for key, expected_value in generated_test_data.attributes_to_test:
360361
assert result[key] == expected_value
361362

362-
def test_delete_cluster_removes_deleted_cluster(
363-
self, cluster_builder, initial_batch_size: int = BatchCountSize.SMALL
364-
) -> None:
363+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
364+
def test_delete_cluster_removes_deleted_cluster(self, cluster_builder, initial_batch_size: int) -> None:
365365
eks_hook, generated_test_data = cluster_builder(count=initial_batch_size, minimal=False)
366366

367367
eks_hook.delete_cluster(name=generated_test_data.existing_cluster_name)
@@ -370,8 +370,9 @@ def test_delete_cluster_removes_deleted_cluster(
370370
assert len(result_cluster_list) == (initial_batch_size - 1)
371371
assert generated_test_data.existing_cluster_name not in result_cluster_list
372372

373+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
373374
def test_delete_cluster_throws_exception_when_cluster_not_found(
374-
self, cluster_builder, initial_batch_size: int = BatchCountSize.SMALL
375+
self, cluster_builder, initial_batch_size: int
375376
) -> None:
376377
eks_hook, generated_test_data = cluster_builder(count=initial_batch_size)
377378
expected_exception: type[AWSError] = ResourceNotFoundException
@@ -399,8 +400,9 @@ def test_list_nodegroups_returns_empty_by_default(self, cluster_builder) -> None
399400
assert isinstance(result, list)
400401
assert len(result) == 0
401402

403+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
402404
def test_list_nodegroups_returns_sorted_nodegroup_names(
403-
self, nodegroup_builder, initial_batch_size: int = BatchCountSize.SMALL
405+
self, nodegroup_builder, initial_batch_size: int
404406
) -> None:
405407
eks_hook, generated_test_data = nodegroup_builder(count=initial_batch_size)
406408
expected_result: list = sorted(generated_test_data.nodegroup_names)
@@ -409,9 +411,8 @@ def test_list_nodegroups_returns_sorted_nodegroup_names(
409411

410412
assert_result_matches_expected_list(result, expected_result, initial_batch_size)
411413

412-
def test_list_nodegroups_returns_all_results(
413-
self, nodegroup_builder, initial_batch_size: int = BatchCountSize.LARGE
414-
) -> None:
414+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.LARGE])
415+
def test_list_nodegroups_returns_all_results(self, nodegroup_builder, initial_batch_size: int) -> None:
415416
eks_hook, generated_test_data = nodegroup_builder(count=initial_batch_size)
416417
expected_result: list = sorted(generated_test_data.nodegroup_names)
417418

@@ -442,8 +443,9 @@ def test_create_nodegroup_throws_exception_when_cluster_not_found(self) -> None:
442443
raised_exception=raised_exception,
443444
)
444445

446+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
445447
def test_create_nodegroup_throws_exception_when_nodegroup_already_exists(
446-
self, nodegroup_builder, initial_batch_size: int = BatchCountSize.SMALL
448+
self, nodegroup_builder, initial_batch_size: int
447449
) -> None:
448450
eks_hook, generated_test_data = nodegroup_builder(count=initial_batch_size)
449451
expected_exception: type[AWSError] = ResourceInUseException
@@ -470,8 +472,9 @@ def test_create_nodegroup_throws_exception_when_nodegroup_already_exists(
470472
)
471473
assert nodegroup_count_after_test == initial_batch_size
472474

475+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
473476
def test_create_nodegroup_throws_exception_when_cluster_not_active(
474-
self, nodegroup_builder, initial_batch_size: int = BatchCountSize.SMALL
477+
self, nodegroup_builder, initial_batch_size: int
475478
) -> None:
476479
eks_hook, generated_test_data = nodegroup_builder(count=initial_batch_size)
477480
non_existent_nodegroup_name: str = NON_EXISTING_NODEGROUP_NAME
@@ -637,8 +640,9 @@ def test_delete_cluster_throws_exception_when_nodegroups_exist(self, nodegroup_b
637640
cluster_count_after_test: int = len(eks_hook.list_clusters())
638641
assert cluster_count_after_test == BatchCountSize.SINGLE
639642

643+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
640644
def test_delete_nodegroup_removes_deleted_nodegroup(
641-
self, nodegroup_builder, initial_batch_size: int = BatchCountSize.SMALL
645+
self, nodegroup_builder, initial_batch_size: int
642646
) -> None:
643647
eks_hook, generated_test_data = nodegroup_builder(count=initial_batch_size)
644648

@@ -651,8 +655,9 @@ def test_delete_nodegroup_removes_deleted_nodegroup(
651655
assert len(result_nodegroup_list) == (initial_batch_size - 1)
652656
assert generated_test_data.existing_nodegroup_name not in result_nodegroup_list
653657

658+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
654659
def test_delete_nodegroup_returns_deleted_nodegroup(
655-
self, nodegroup_builder, initial_batch_size: int = BatchCountSize.SMALL
660+
self, nodegroup_builder, initial_batch_size: int
656661
) -> None:
657662
eks_hook, generated_test_data = nodegroup_builder(count=initial_batch_size, minimal=False)
658663

@@ -683,8 +688,9 @@ def test_delete_nodegroup_throws_exception_when_cluster_not_found(self, nodegrou
683688
raised_exception=raised_exception,
684689
)
685690

691+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
686692
def test_delete_nodegroup_throws_exception_when_nodegroup_not_found(
687-
self, nodegroup_builder, initial_batch_size: int = BatchCountSize.SMALL
693+
self, nodegroup_builder, initial_batch_size: int
688694
) -> None:
689695
eks_hook, generated_test_data = nodegroup_builder(count=initial_batch_size)
690696
expected_exception: type[AWSError] = ResourceNotFoundException
@@ -806,8 +812,9 @@ def test_list_fargate_profiles_returns_empty_by_default(self, cluster_builder) -
806812
assert isinstance(result, list)
807813
assert len(result) == 0
808814

815+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
809816
def test_list_fargate_profiles_returns_sorted_profile_names(
810-
self, fargate_profile_builder, initial_batch_size: int = BatchCountSize.SMALL
817+
self, fargate_profile_builder, initial_batch_size: int
811818
) -> None:
812819
eks_hook, generated_test_data = fargate_profile_builder(count=initial_batch_size)
813820
expected_result: list = sorted(generated_test_data.fargate_profile_names)
@@ -816,8 +823,9 @@ def test_list_fargate_profiles_returns_sorted_profile_names(
816823

817824
assert_result_matches_expected_list(result, expected_result, initial_batch_size)
818825

826+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.LARGE])
819827
def test_list_fargate_profiles_returns_all_results(
820-
self, fargate_profile_builder, initial_batch_size: int = BatchCountSize.LARGE
828+
self, fargate_profile_builder, initial_batch_size: int
821829
) -> None:
822830
eks_hook, generated_test_data = fargate_profile_builder(count=initial_batch_size)
823831
expected_result: list = sorted(generated_test_data.fargate_profile_names)
@@ -847,8 +855,9 @@ def test_create_fargate_profile_throws_exception_when_cluster_not_found(self) ->
847855
raised_exception=raised_exception,
848856
)
849857

858+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
850859
def test_create_fargate_profile_throws_exception_when_fargate_profile_already_exists(
851-
self, fargate_profile_builder, initial_batch_size: int = BatchCountSize.SMALL
860+
self, fargate_profile_builder, initial_batch_size: int
852861
) -> None:
853862
eks_hook, generated_test_data = fargate_profile_builder(count=initial_batch_size)
854863
expected_exception: type[AWSError] = ResourceInUseException
@@ -872,8 +881,9 @@ def test_create_fargate_profile_throws_exception_when_fargate_profile_already_ex
872881
)
873882
assert fargate_profile_count_after_test == initial_batch_size
874883

884+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
875885
def test_create_fargate_profile_throws_exception_when_cluster_not_active(
876-
self, fargate_profile_builder, initial_batch_size: int = BatchCountSize.SMALL
886+
self, fargate_profile_builder, initial_batch_size: int
877887
) -> None:
878888
eks_hook, generated_test_data = fargate_profile_builder(count=initial_batch_size)
879889
non_existent_fargate_profile_name: str = NON_EXISTING_FARGATE_PROFILE_NAME
@@ -976,8 +986,9 @@ def test_describe_fargate_profile_throws_exception_when_profile_not_found(
976986
raised_exception=raised_exception,
977987
)
978988

989+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
979990
def test_delete_fargate_profile_removes_deleted_fargate_profile(
980-
self, fargate_profile_builder, initial_batch_size: int = BatchCountSize.SMALL
991+
self, fargate_profile_builder, initial_batch_size: int
981992
) -> None:
982993
eks_hook, generated_test_data = fargate_profile_builder(initial_batch_size)
983994

@@ -992,8 +1003,9 @@ def test_delete_fargate_profile_removes_deleted_fargate_profile(
9921003
assert len(result_fargate_profile_list) == (initial_batch_size - 1)
9931004
assert generated_test_data.existing_fargate_profile_name not in result_fargate_profile_list
9941005

1006+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
9951007
def test_delete_fargate_profile_returns_deleted_fargate_profile(
996-
self, fargate_profile_builder, initial_batch_size: int = BatchCountSize.SMALL
1008+
self, fargate_profile_builder, initial_batch_size: int
9971009
) -> None:
9981010
eks_hook, generated_test_data = fargate_profile_builder(count=initial_batch_size, minimal=False)
9991011

@@ -1026,8 +1038,9 @@ def test_delete_fargate_profile_throws_exception_when_cluster_not_found(
10261038
raised_exception=raised_exception,
10271039
)
10281040

1041+
@pytest.mark.parametrize("initial_batch_size", [BatchCountSize.SMALL])
10291042
def test_delete_fargate_profile_throws_exception_when_fargate_profile_not_found(
1030-
self, fargate_profile_builder, initial_batch_size: int = BatchCountSize.SMALL
1043+
self, fargate_profile_builder, initial_batch_size: int
10311044
) -> None:
10321045
eks_hook, generated_test_data = fargate_profile_builder(count=initial_batch_size)
10331046
expected_exception: type[AWSError] = ResourceNotFoundException
@@ -1360,6 +1373,3 @@ def assert_is_valid_uri(value: str) -> None:
13601373

13611374
assert all([result.scheme, result.netloc, result.path])
13621375
assert REGION in value
1363-
1364-
1365-
# ruff: noqa: PT028

0 commit comments

Comments
 (0)