Skip to content

Commit

Permalink
Fix unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
knikure committed Jun 18, 2024
1 parent c5efd7c commit 28d9e12
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tests/unit/sagemaker/huggingface/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def test_huggingface(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
huggingface_training_version, f"pytorch{huggingface_pytorch_training_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def test_pytorchxla_distribution(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
huggingface_training_compiler_version,
Expand Down Expand Up @@ -463,7 +463,7 @@ def test_default_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
huggingface_training_compiler_version,
Expand Down Expand Up @@ -519,7 +519,7 @@ def test_debug_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
huggingface_training_compiler_version,
Expand Down Expand Up @@ -575,7 +575,7 @@ def test_disable_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
huggingface_training_compiler_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def test_default_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
huggingface_training_compiler_version,
Expand Down Expand Up @@ -407,7 +407,7 @@ def test_debug_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
huggingface_training_compiler_version,
Expand Down Expand Up @@ -465,7 +465,7 @@ def test_disable_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
huggingface_training_compiler_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def test_pytorchxla_distribution(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
pytorch_training_compiler_version,
Expand Down Expand Up @@ -403,7 +403,7 @@ def test_default_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
pytorch_training_compiler_version,
Expand Down Expand Up @@ -458,7 +458,7 @@ def test_debug_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
pytorch_training_compiler_version,
Expand Down Expand Up @@ -513,7 +513,7 @@ def test_disable_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
pytorch_training_compiler_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def test_default(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
tensorflow_training_version,
Expand Down Expand Up @@ -348,7 +348,7 @@ def test_byoc(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
tensorflow_training_version,
Expand Down Expand Up @@ -399,7 +399,7 @@ def test_debug_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
tensorflow_training_version,
Expand Down Expand Up @@ -450,7 +450,7 @@ def test_disable_compiler_config(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
tensorflow_training_version,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_chainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def test_chainer(strftime, time, sagemaker_session, chainer_version, chainer_py_
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(chainer_version, chainer_py_version)
expected_train_args["input_config"][0]["DataSource"]["S3DataSource"]["S3Uri"] = inputs
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def test_mxnet(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

actual_train_args = sagemaker_session.method_calls[0][2]
job_name = actual_train_args["job_name"]
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ def uploaded_code(
return UploadedCode(s3_prefix=s3_prefix, script_name=script_name)


@pytest.fixture(auto_use=True)
def mock_process_studio_metadata_file():
with patch(
"sagemaker.user_agent.process_studio_metadata_file", MagicMock()
) as process_studio_metadata_file:
yield process_studio_metadata_file


@patch("sagemaker.utils._botocore_resolver")
@patch("os.path.exists", return_value=True)
@patch("os.path.isfile", return_value=True)
Expand Down Expand Up @@ -277,15 +285,13 @@ def test_sklearn_with_all_parameters_via_run_args(
sagemaker_session.process.assert_called_with(**expected_args)


@patch("sagemaker.user_agent.process_studio_metadata_file", return_value="TestApp")
@patch("sagemaker.utils._botocore_resolver")
@patch("os.path.exists", return_value=True)
@patch("os.path.isfile", return_value=True)
def test_sklearn_with_all_parameters_via_run_args_called_twice(
exists_mock,
isfile_mock,
botocore_resolver,
process_studio_metadata_file_mock,
sklearn_version,
sagemaker_session,
):
Expand Down Expand Up @@ -338,15 +344,13 @@ def test_sklearn_with_all_parameters_via_run_args_called_twice(
sagemaker_session.process.assert_called_with(**expected_args)


@patch("sagemaker.user_agent.process_studio_metadata_file", return_value="TestApp")
@patch("sagemaker.utils._botocore_resolver")
@patch("os.path.exists", return_value=True)
@patch("os.path.isfile", return_value=True)
def test_pytorch_processor_with_required_parameters(
exists_mock,
isfile_mock,
botocore_resolver,
process_studio_metadata_file_mock,
sagemaker_session,
pytorch_training_version,
pytorch_training_py_version,
Expand Down Expand Up @@ -418,14 +422,12 @@ def test_xgboost_processor_with_required_parameters(
sagemaker_session.process.assert_called_with(**expected_args)


@patch("sagemaker.user_agent.process_studio_metadata_file", return_value="TestApp")
@patch("sagemaker.utils._botocore_resolver")
@patch("os.path.exists", return_value=True)
@patch("os.path.isfile", return_value=True)
def test_mxnet_processor_with_required_parameters(
exists_mock,
isfile_mock,
process_studio_metadata_file_mock,
botocore_resolver,
sagemaker_session,
mxnet_training_version,
Expand Down Expand Up @@ -468,15 +470,13 @@ def test_mxnet_processor_with_required_parameters(
sagemaker_session.process.assert_called_with(**expected_args)


@patch("sagemaker.user_agent.process_studio_metadata_file", return_value="TestApp")
@patch("sagemaker.utils._botocore_resolver")
@patch("os.path.exists", return_value=True)
@patch("os.path.isfile", return_value=True)
def test_tensorflow_processor_with_required_parameters(
exists_mock,
isfile_mock,
botocore_resolver,
process_studio_metadata_file_mock,
sagemaker_session,
tensorflow_training_version,
tensorflow_training_py_version,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def test_pytorch(
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(pytorch_inference_version, pytorch_inference_py_version)
expected_train_args["input_config"][0]["DataSource"]["S3DataSource"]["S3Uri"] = inputs
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_rl.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test_rl(time, strftime, sagemaker_session, coach_mxnet_version):
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
RLToolkit.COACH.value, coach_mxnet_version, RLFramework.MXNET.value
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_sklearn(time, strftime, sagemaker_session, sklearn_version):
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(sklearn_version)
expected_train_args["input_config"][0]["DataSource"]["S3DataSource"]["S3Uri"] = inputs
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_xgboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def test_xgboost_cpu(time, strftime, sagemaker_session, xgboost_framework_versio
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(xgboost_framework_version)
expected_train_args["input_config"][0]["DataSource"]["S3DataSource"]["S3Uri"] = inputs
Expand Down Expand Up @@ -377,7 +377,7 @@ def test_xgboost_gpu(time, strftime, sagemaker_session, xgboost_gpu_framework_ve
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(
xgboost_gpu_framework_version, instance_type=GPU_INSTANCE_TYPE
Expand Down Expand Up @@ -427,7 +427,7 @@ def test_distributed_training(time, strftime, sagemaker_session, xgboost_framewo
sagemaker_call_names = [c[0] for c in sagemaker_session.method_calls]
assert sagemaker_call_names == ["train", "logs_for_job"]
boto_call_names = [c[0] for c in sagemaker_session.boto_session.method_calls]
assert boto_call_names == ["resource"]
assert boto_call_names == ["resource", "client"]

expected_train_args = _create_train_job(xgboost_framework_version, DIST_INSTANCE_COUNT)
expected_train_args["input_config"][0]["DataSource"]["S3DataSource"]["S3Uri"] = inputs
Expand Down

0 comments on commit 28d9e12

Please sign in to comment.