From 041ab8a00e68ffb24ce12b6f0c9115eaf0fb3139 Mon Sep 17 00:00:00 2001 From: gchqdev227 <62302861+gchqdev227@users.noreply.github.com> Date: Fri, 20 Feb 2026 11:00:59 +0000 Subject: [PATCH 1/2] Replaced calls to moto internals with correct use of the moto internal API --- tests/test_examples.py | 61 ++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/tests/test_examples.py b/tests/test_examples.py index 708f910..442e809 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -7,7 +7,7 @@ import os from pathlib import Path from tempfile import TemporaryDirectory -from typing import TYPE_CHECKING, Any +from typing import Any import unittest import unittest.mock import urllib.parse @@ -18,7 +18,9 @@ import botocore # noqa: F401 from dateutil.tz import tzlocal from moto import mock_aws - from moto.sagemaker.models import FakePipelineExecution + from moto.core import DEFAULT_ACCOUNT_ID + from moto.sagemaker.models import sagemaker_backends + from moto.sagemaker.utils import get_pipeline_execution_from_arn, get_pipeline_from_name import requests # noqa: F401 import urllib3 # noqa: F401 except ImportError: @@ -37,9 +39,6 @@ from examples.secrets import SecretVersion from examples.xkcd import ComicVersion, XKCDResource -if TYPE_CHECKING: - from moto.sagemaker.responses import TYPE_RESPONSE, SageMakerResponse - def setUpModule() -> None: """Code to run before any single test in the module is run.""" @@ -448,6 +447,7 @@ def setUp(self) -> None: pipeline_arn = "arn:aws:sagemaker:eu-west-1::pipeline:my-pipeline" self.resource = PipelineResource(pipeline_arn) client = self.resource._client + self._moto_backend = sagemaker_backends[DEFAULT_ACCOUNT_ID][client.meta.region_name] pipeline_definition = { "Version": "2020-12-01", @@ -479,35 +479,29 @@ def setUp(self) -> None: self.execution_arns = execution_arns[::-1] # reverse these to force moto to yield in descending order - def test_fetch_secret_no_version(self) -> None: + def test_fetch_no_version(self) -> None: version, = self.resource.fetch_new_versions() expected_version = ExecutionVersion(self.execution_arns[-1]) self.assertEqual(version, expected_version) - def test_fetch_secret_no_available_versions(self) -> None: - with unittest.mock.patch("moto.sagemaker.responses.SageMakerResponse.list_pipeline_executions", - _new_response_list_pipeline_executions_empty): - versions = self.resource.fetch_new_versions() + def test_fetch_no_available_versions(self) -> None: + pipeline = get_pipeline_from_name(self._moto_backend.pipelines, self.resource.pipeline_name) + pipeline.pipeline_executions.clear() + versions = self.resource.fetch_new_versions() self.assertListEqual(versions, []) - def test_fetch_secret_no_version_with_pending(self) -> None: - fake_pipeline_executions: list[FakePipelineExecution] = FakePipelineExecution.instances - execution_mapping = {execution.pipeline_execution_arn: execution for execution in fake_pipeline_executions} - + def test_fetch_no_version_with_pending(self) -> None: for execution_arn in self.execution_arns[3:]: - execution = execution_mapping[execution_arn] + execution = get_pipeline_execution_from_arn(self._moto_backend.pipelines, execution_arn) execution.pipeline_execution_status = "Executing" version, = self.resource.fetch_new_versions() expected_version = ExecutionVersion(self.execution_arns[2]) self.assertEqual(version, expected_version) - def test_fetch_secret_no_version_with_pending_and_all_statuses(self) -> None: - fake_pipeline_executions: list[FakePipelineExecution] = FakePipelineExecution.instances - execution_mapping = {execution.pipeline_execution_arn: execution for execution in fake_pipeline_executions} - + def test_fetch_no_version_with_pending_and_all_statuses(self) -> None: for execution_arn in self.execution_arns[3:]: - execution = execution_mapping[execution_arn] + execution = get_pipeline_execution_from_arn(self._moto_backend.pipelines, execution_arn) execution.pipeline_execution_status = "Executing" self.resource.statuses.append("Executing") @@ -516,13 +510,13 @@ def test_fetch_secret_no_version_with_pending_and_all_statuses(self) -> None: expected_version = ExecutionVersion(self.execution_arns[-1]) self.assertEqual(version, expected_version) - def test_fetch_secret_latest_version(self) -> None: + def test_fetch_latest_version(self) -> None: previous_version, = self.resource.fetch_new_versions() version, = self.resource.fetch_new_versions(previous_version) expected_version = ExecutionVersion(self.execution_arns[-1]) self.assertEqual(version, expected_version) - def test_fetch_secret_old_version(self) -> None: + def test_fetch_old_version(self) -> None: previous_version = ExecutionVersion(self.execution_arns[2]) versions = self.resource.fetch_new_versions(previous_version) expected_versions = [ExecutionVersion(arn) for arn in self.execution_arns[2:]] @@ -542,6 +536,7 @@ def setUp(self) -> None: pipeline_name = "my-pipeline" resource = PipelineResource("arn:aws:sagemaker:eu-west-1::pipeline:my-pipeline") client = resource._client + self._moto_backend = sagemaker_backends[DEFAULT_ACCOUNT_ID][client.meta.region_name] self.pipeline_definition = { "Version": "2020-12-01", @@ -611,11 +606,8 @@ def test_download_maximum_info(self) -> None: self.assertDictEqual(metadata, expected_metadata) def test_download_failed_execution(self) -> None: - fake_pipeline_executions: list[FakePipelineExecution] = FakePipelineExecution.instances - execution_mapping = {execution.pipeline_execution_arn: execution for execution in fake_pipeline_executions} - - fake_execution = execution_mapping[self.version_minimum.execution_arn] - fake_execution.pipeline_execution_status = "Failed" + execution = get_pipeline_execution_from_arn(self._moto_backend.pipelines, self.version_minimum.execution_arn) + execution.pipeline_execution_status = "Failed" resource = PipelineResource(pipeline="arn:aws:sagemaker:eu-west-1::pipeline:my-pipeline") wrapper = SimpleTestResourceWrapper(resource) @@ -675,20 +667,13 @@ def setUp(self) -> None: ) def test_execution_creation(self) -> None: - fake_pipeline_executions: list[FakePipelineExecution] = FakePipelineExecution.instances - initial_execution_mapping = {execution.pipeline_execution_arn: execution for execution in fake_pipeline_executions} + intitial_executions = {version.execution_arn for version in self.resource._yield_potential_execution_versions()} resource = PipelineResource(pipeline="arn:aws:sagemaker:eu-west-1::pipeline:my-pipeline") wrapper = SimpleTestResourceWrapper(resource) new_version, _ = wrapper.publish_new_version() - execution_mapping = {execution.pipeline_execution_arn: execution for execution in fake_pipeline_executions} - self.assertNotIn(new_version.execution_arn, initial_execution_mapping) - self.assertIn(new_version.execution_arn, execution_mapping) - + new_executions = {version.execution_arn for version in self.resource._yield_potential_execution_versions()} -def _new_response_list_pipeline_executions_empty(self: SageMakerResponse) -> TYPE_RESPONSE: - response: dict[str, object] = { - "PipelineExecutionSummaries": [], - } - return 200, {}, json.dumps(response) + self.assertNotIn(new_version.execution_arn, intitial_executions) + self.assertIn(new_version.execution_arn, new_executions) From b24246b7b2d835445ffff9f8c54b84162e6cf60a Mon Sep 17 00:00:00 2001 From: gchqdev227 <62302861+gchqdev227@users.noreply.github.com> Date: Fri, 20 Feb 2026 11:01:16 +0000 Subject: [PATCH 2/2] Bumped test dependencies, including moto dependency --- requirements-tests.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 6c3b47f..7cbbac5 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,21 +1,21 @@ -boto3==1.42.24 -botocore==1.42.24 +boto3==1.42.53 +botocore==1.42.53 certifi==2026.1.4 cffi==2.0.0 charset-normalizer==3.4.4 -cryptography==46.0.3 +cryptography==46.0.5 idna==3.11 Jinja2==3.1.6 -jmespath==1.0.1 +jmespath==1.1.0 MarkupSafe==3.0.3 -moto==5.0.12 -pycparser==2.23 +moto==5.1.21 +pycparser==3.0 python-dateutil==2.9.0.post0 PyYAML==6.0.3 requests==2.32.5 -responses==0.25.8 +responses==0.26.0 s3transfer==0.16.0 six==1.17.0 urllib3==2.6.3 -Werkzeug==3.1.5 -xmltodict==1.0.2 +Werkzeug==3.1.6 +xmltodict==1.0.3