Skip to content

Commit

Permalink
fix fixture mock
Browse files Browse the repository at this point in the history
  • Loading branch information
knikure committed Jun 18, 2024
1 parent 8bba425 commit addd339
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
7 changes: 4 additions & 3 deletions tests/unit/sagemaker/huggingface/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from sagemaker.huggingface.processing import HuggingFaceProcessor
from sagemaker.fw_utils import UploadedCode
from sagemaker.session_settings import SessionSettings
from sagemaker.user_agent import process_studio_metadata_file

from .huggingface_utils import get_full_gpu_image_uri, GPU_INSTANCE_TYPE, REGION

Expand Down Expand Up @@ -68,11 +69,11 @@ def uploaded_code(
@pytest.fixture(autouse=True)
def mock_process_studio_metadata_file(tmp_path):
studio_file = tmp_path / "resource-metadata.json"
studio_file.write_text(json.dumps({"AppType": "studio_type"}))
studio_file.write_text(json.dumps({"AppType": "TestAppType"}))

with patch("os.path.exists", return_value=True):
with patch("builtins.open", mock_open(read_data=studio_file.read_text())):
yield
with patch("sagemaker.user_agent.open", mock_open(read_data=studio_file.read_text())):
yield process_studio_metadata_file


@patch("sagemaker.utils._botocore_resolver")
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/sagemaker/workflow/test_processing_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from sagemaker.network import NetworkConfig
from sagemaker.pytorch.estimator import PyTorch
from sagemaker import utils, Model
from sagemaker.user_agent import process_studio_metadata_file

from sagemaker.clarify import (
SageMakerClarifyProcessor,
Expand Down Expand Up @@ -247,14 +248,13 @@ def network_config():
)


@pytest.fixture(autouse=True)
def mock_process_studio_metadata_file(tmp_path):
studio_file = tmp_path / "resource-metadata.json"
studio_file.write_text(json.dumps({"AppType": "studio_type"}))
studio_file.write_text(json.dumps({"AppType": "TestAppType"}))

with patch("os.path.exists", return_value=True):
with patch("builtins.open", mock_open(read_data=studio_file.read_text())):
yield
with patch("sagemaker.user_agent.open", mock_open(read_data=studio_file.read_text())):
yield process_studio_metadata_file


@pytest.mark.parametrize(
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from sagemaker.workflow.pipeline_context import PipelineSession, _PipelineConfig
from sagemaker.workflow.functions import Join
from sagemaker.workflow.execution_variables import ExecutionVariables
from sagemaker.user_agent import process_studio_metadata_file
from tests.unit import SAGEMAKER_CONFIG_PROCESSING_JOB

BUCKET_NAME = "mybucket"
Expand Down Expand Up @@ -137,11 +138,11 @@ def uploaded_code(
@pytest.fixture(autouse=True)
def mock_process_studio_metadata_file(tmp_path):
studio_file = tmp_path / "resource-metadata.json"
studio_file.write_text(json.dumps({"AppType": "studio_type"}))
studio_file.write_text(json.dumps({"AppType": "TestAppType"}))

with patch("os.path.exists", return_value=True):
with patch("builtins.open", mock_open(read_data=studio_file.read_text())):
yield
with patch("sagemaker.user_agent.open", mock_open(read_data=studio_file.read_text())):
yield process_studio_metadata_file


@patch("sagemaker.utils._botocore_resolver")
Expand Down

0 comments on commit addd339

Please sign in to comment.