Skip to content

Commit 4f1aad2

Browse files
committed
style: Black-format two test files merged from master
test_load_or_create.py (core) and test_pipeline_class.py (mlops) landed on master via aws#6256 after this branch's black pass and were pulled in unformatted by the merge commit, failing black-check in CI. --- X-AI-Prompt: fix failing codestyle-doc-tests reruns on PR aws#6294 X-AI-Tool: Kiro
1 parent de8b0b8 commit 4f1aad2

2 files changed

Lines changed: 36 additions & 33 deletions

File tree

‎sagemaker-core/tests/unit/experiments/test_load_or_create.py‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
already-exists branch against BOTH wordings so a future wording change cannot
1818
silently turn load-or-create back into a hard failure.
1919
"""
20+
2021
from __future__ import absolute_import
2122

2223
import pytest
@@ -27,15 +28,12 @@
2728
from sagemaker.core.experiments.trial import _Trial
2829
from sagemaker.core.experiments.trial_component import _TrialComponent
2930

30-
3131
LEGACY_MESSAGE = "Experiment exp-1 already exists"
3232
NEW_MESSAGE = "Experiment names must be unique within an AWS account and region"
3333

3434

3535
def _validation_error(message):
36-
return ClientError(
37-
{"Error": {"Code": "ValidationException", "Message": message}}, "create"
38-
)
36+
return ClientError({"Error": {"Code": "ValidationException", "Message": message}}, "create")
3937

4038

4139
@pytest.mark.parametrize("message", [LEGACY_MESSAGE, NEW_MESSAGE])
@@ -74,9 +72,7 @@ def test_trial_load_or_create_loads_on_duplicate_name(message):
7472
def test_trial_component_load_or_create_loads_on_duplicate_name(message):
7573
with patch.object(_TrialComponent, "create", side_effect=_validation_error(message)):
7674
with patch.object(_TrialComponent, "load") as mock_load:
77-
result, is_existed = _TrialComponent._load_or_create(
78-
trial_component_name="tc-1"
79-
)
75+
result, is_existed = _TrialComponent._load_or_create(trial_component_name="tc-1")
8076

8177
mock_load.assert_called_once_with("tc-1", None)
8278
assert result is mock_load.return_value

‎sagemaker-mlops/tests/unit/workflow/test_pipeline_class.py‎

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,7 @@ def test_upsert_updates_existing_pipeline(self, mock_session):
422422
# Verify tags were merged and added
423423
mock_session.sagemaker_client.add_tags.assert_called_once()
424424

425-
def test_upsert_updates_existing_pipeline_with_names_must_be_unique_message(
426-
self, mock_session
427-
):
425+
def test_upsert_updates_existing_pipeline_with_names_must_be_unique_message(self, mock_session):
428426
"""Upsert must also recognize the newer service wording 'names must be unique'."""
429427
error_response = {
430428
"Error": {
@@ -436,11 +434,15 @@ def test_upsert_updates_existing_pipeline_with_names_must_be_unique_message(
436434
mock_session.sagemaker_client.list_tags = Mock(return_value={"Tags": []})
437435
mock_session.sagemaker_client.add_tags = Mock()
438436

439-
with patch.object(Pipeline, 'create') as mock_create:
440-
with patch.object(Pipeline, 'update') as mock_update:
441-
with patch('sagemaker.mlops.workflow.pipeline.resolve_value_from_config') as mock_resolve:
442-
with patch('sagemaker.mlops.workflow.pipeline.resolve_and_validate_role') as mock_validate:
443-
with patch('sagemaker.mlops.workflow.pipeline.format_tags') as mock_format:
437+
with patch.object(Pipeline, "create") as mock_create:
438+
with patch.object(Pipeline, "update") as mock_update:
439+
with patch(
440+
"sagemaker.mlops.workflow.pipeline.resolve_value_from_config"
441+
) as mock_resolve:
442+
with patch(
443+
"sagemaker.mlops.workflow.pipeline.resolve_and_validate_role"
444+
) as mock_validate:
445+
with patch("sagemaker.mlops.workflow.pipeline.format_tags") as mock_format:
444446
mock_resolve.return_value = "arn:aws:iam::123:role/SageMakerRole"
445447
mock_validate.return_value = "arn:aws:iam::123:role/SageMakerRole"
446448
mock_format.return_value = []
@@ -450,8 +452,7 @@ def test_upsert_updates_existing_pipeline_with_names_must_be_unique_message(
450452
}
451453

452454
pipeline = Pipeline(
453-
name="test-pipeline",
454-
sagemaker_session=mock_session
455+
name="test-pipeline", sagemaker_session=mock_session
455456
)
456457

457458
result = pipeline.upsert(role_arn="arn:aws:iam::123:role/SageMakerRole")
@@ -475,11 +476,15 @@ def test_upsert_of_existing_pipeline_does_not_log_error_hint(self, mock_session,
475476
)
476477
mock_session.sagemaker_client.list_tags = Mock(return_value={"Tags": []})
477478

478-
with patch.object(Pipeline, 'update') as mock_update:
479-
with patch.object(Pipeline, '_create_args') as mock_args:
480-
with patch('sagemaker.mlops.workflow.pipeline.resolve_value_from_config') as mock_resolve:
481-
with patch('sagemaker.mlops.workflow.pipeline.resolve_and_validate_role') as mock_validate:
482-
with patch('sagemaker.mlops.workflow.pipeline.format_tags') as mock_format:
479+
with patch.object(Pipeline, "update") as mock_update:
480+
with patch.object(Pipeline, "_create_args") as mock_args:
481+
with patch(
482+
"sagemaker.mlops.workflow.pipeline.resolve_value_from_config"
483+
) as mock_resolve:
484+
with patch(
485+
"sagemaker.mlops.workflow.pipeline.resolve_and_validate_role"
486+
) as mock_validate:
487+
with patch("sagemaker.mlops.workflow.pipeline.format_tags") as mock_format:
483488
mock_resolve.return_value = "arn:aws:iam::123:role/SageMakerRole"
484489
mock_validate.return_value = "arn:aws:iam::123:role/SageMakerRole"
485490
mock_format.return_value = []
@@ -489,12 +494,13 @@ def test_upsert_of_existing_pipeline_does_not_log_error_hint(self, mock_session,
489494
}
490495

491496
pipeline = Pipeline(
492-
name="test-pipeline",
493-
sagemaker_session=mock_session
497+
name="test-pipeline", sagemaker_session=mock_session
494498
)
495499

496500
with caplog.at_level(logging.ERROR):
497-
result = pipeline.upsert(role_arn="arn:aws:iam::123:role/SageMakerRole")
501+
result = pipeline.upsert(
502+
role_arn="arn:aws:iam::123:role/SageMakerRole"
503+
)
498504

499505
assert "PipelineArn" in result
500506
mock_update.assert_called_once()
@@ -515,19 +521,20 @@ def test_bare_create_of_existing_pipeline_logs_error_hint(self, mock_session, ca
515521
side_effect=ClientError(error_response, "create_pipeline")
516522
)
517523

518-
with patch.object(Pipeline, '_create_args') as mock_args:
519-
with patch('sagemaker.mlops.workflow.pipeline.resolve_value_from_config') as mock_resolve:
520-
with patch('sagemaker.mlops.workflow.pipeline.resolve_and_validate_role') as mock_validate:
521-
with patch('sagemaker.mlops.workflow.pipeline.format_tags') as mock_format:
524+
with patch.object(Pipeline, "_create_args") as mock_args:
525+
with patch(
526+
"sagemaker.mlops.workflow.pipeline.resolve_value_from_config"
527+
) as mock_resolve:
528+
with patch(
529+
"sagemaker.mlops.workflow.pipeline.resolve_and_validate_role"
530+
) as mock_validate:
531+
with patch("sagemaker.mlops.workflow.pipeline.format_tags") as mock_format:
522532
mock_resolve.return_value = "arn:aws:iam::123:role/SageMakerRole"
523533
mock_validate.return_value = "arn:aws:iam::123:role/SageMakerRole"
524534
mock_format.return_value = []
525535
mock_args.return_value = {"PipelineName": "test-pipeline"}
526536

527-
pipeline = Pipeline(
528-
name="test-pipeline",
529-
sagemaker_session=mock_session
530-
)
537+
pipeline = Pipeline(name="test-pipeline", sagemaker_session=mock_session)
531538

532539
with caplog.at_level(logging.ERROR):
533540
with pytest.raises(ClientError):

0 commit comments

Comments
 (0)