Skip to content

Commit 4a1c53c

Browse files
author
Verdi March
committed
Unit test framework processor with source_dir and dependencies
1 parent ca8490a commit 4a1c53c

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

tests/unit/test_processing.py

+23-12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from sagemaker.sklearn.processing import SKLearnProcessor
3232
from sagemaker.network import NetworkConfig
3333
from sagemaker.processing import FeatureStoreOutput
34+
from sagemaker.fw_utils import UploadedCode
3435

3536
BUCKET_NAME = "mybucket"
3637
REGION = "us-west-2"
@@ -67,6 +68,14 @@ def sagemaker_session():
6768
return session_mock
6869

6970

71+
@pytest.fixture()
72+
def uploaded_code(
73+
s3_prefix="s3://mocked_s3_uri_from_upload_data/my_job_name/source/sourcedir.tar.gz",
74+
script_name="processing_code.py",
75+
):
76+
return UploadedCode(s3_prefix=s3_prefix, script_name=script_name)
77+
78+
7079
@patch("sagemaker.utils._botocore_resolver")
7180
@patch("os.path.exists", return_value=True)
7281
@patch("os.path.isfile", return_value=True)
@@ -99,7 +108,7 @@ def test_sklearn_processor_with_required_parameters(
99108
@patch("os.path.exists", return_value=True)
100109
@patch("os.path.isfile", return_value=True)
101110
def test_sklearn_with_all_parameters(
102-
exists_mock, isfile_mock, botocore_resolver, sklearn_version, sagemaker_session
111+
exists_mock, isfile_mock, botocore_resolver, sklearn_version, sagemaker_session, uploaded_code
103112
):
104113
botocore_resolver.return_value.construct_endpoint.return_value = {"hostname": ECR_HOSTNAME}
105114

@@ -126,17 +135,19 @@ def test_sklearn_with_all_parameters(
126135
sagemaker_session=sagemaker_session,
127136
)
128137

129-
processor.run(
130-
entry_point="/local/path/to/processing_code.py",
131-
# TODO: Add a source_dir in a way that the processor can validate it (fictional won't do)
132-
inputs=_get_data_inputs_all_parameters(),
133-
outputs=_get_data_outputs_all_parameters(),
134-
arguments=["--drop-columns", "'SelfEmployed'"],
135-
wait=True,
136-
logs=False,
137-
job_name="my_job_name",
138-
experiment_config={"ExperimentName": "AnExperiment"},
139-
)
138+
with patch("sagemaker.estimator.tar_and_upload_dir", return_value=uploaded_code):
139+
processor.run(
140+
entry_point="processing_code.py",
141+
source_dir="/local/path/to/source_dir",
142+
dependencies=["/local/path/to/dep_01"],
143+
inputs=_get_data_inputs_all_parameters(),
144+
outputs=_get_data_outputs_all_parameters(),
145+
arguments=["--drop-columns", "'SelfEmployed'"],
146+
wait=True,
147+
logs=False,
148+
job_name="my_job_name",
149+
experiment_config={"ExperimentName": "AnExperiment"},
150+
)
140151

141152
expected_args = _get_expected_args_all_parameters_modular_code(processor._current_job_name)
142153
sklearn_image_uri = (

0 commit comments

Comments
 (0)