Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 55 additions & 20 deletions tests/unitary/with_extras/model/test_env_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,24 +181,30 @@ def test_from_slug_not_exist(self, mock_get_service_packs):
"mlcpuv1": ("test_path", "3.6"),
},
)
with pytest.raises(
ValueError,
match="conda environment slug `not_exist` could not be resolved",
):
with pytest.raises(ValueError) as exc_info:
TrainingEnvInfo.from_slug(
"not_exist", namespace="ociodscdev", bucketname="service-conda-packs"
)
error_message = str(exc_info.value)
assert (
"conda environment slug `not_exist` could not be resolved" in error_message
)
assert "full OCI path from Environment Explorer" in error_message

@patch("ads.model.runtime.env_info.get_service_packs")
def test_from_slug_service_pack_list_not_extracted(self, mock_get_service_packs):
mock_get_service_packs.return_value = ({}, {})
with pytest.raises(
ValueError,
match="service conda environment list could not be extracted",
):
with pytest.raises(ValueError) as exc_info:
TrainingEnvInfo.from_slug(
"mlcpuv1", namespace="ociodscdev", bucketname="service-conda-packs"
)
error_message = str(exc_info.value)
assert (
"service conda environment list could not be extracted" in error_message
)
assert (
"full conda environment path from Environment Explorer" in error_message
)

@patch("ads.model.runtime.env_info.get_service_packs")
@patch("ads.model.runtime.env_info.utils.is_path_exists", return_value=True)
Expand Down Expand Up @@ -249,11 +255,17 @@ def test_from_path(
@patch("ads.model.runtime.env_info.utils.is_path_exists", return_value=False)
def test_from_path_not_accessible(self, _mock_is_path_exists, mock_get_service_packs):
env_path = "oci://license_checker@ociodscdev/conda/missing"
with pytest.raises(
ValueError,
match="conda environment path `oci://license_checker@ociodscdev/conda/missing` does not exist or is not accessible",
):
with pytest.raises(ValueError) as exc_info:
TrainingEnvInfo.from_path(env_path, auth={"signer": object()})
error_message = str(exc_info.value)
assert f"conda environment path `{env_path}`" in error_message
assert "does not exist or is not accessible" in error_message
assert (
"valid full conda environment path from Environment Explorer"
in error_message
)
assert "service conda environment list" not in error_message
assert "conda environment slug" not in error_message
mock_get_service_packs.assert_not_called()

def test_from_dict(self):
Expand Down Expand Up @@ -330,24 +342,30 @@ def test_from_slug_not_exist(self, mock_get_service_packs):
"mlcpuv1": ("test_path", "3.6"),
},
)
with pytest.raises(
ValueError,
match="conda environment slug `not_exist` could not be resolved",
):
with pytest.raises(ValueError) as exc_info:
InferenceEnvInfo.from_slug(
"not_exist", namespace="ociodscdev", bucketname="service-conda-packs"
)
error_message = str(exc_info.value)
assert (
"conda environment slug `not_exist` could not be resolved" in error_message
)
assert "full OCI path from Environment Explorer" in error_message

@patch("ads.model.runtime.env_info.get_service_packs")
def test_from_slug_service_pack_list_not_extracted(self, mock_get_service_packs):
mock_get_service_packs.return_value = ({}, {})
with pytest.raises(
ValueError,
match="service conda environment list could not be extracted",
):
with pytest.raises(ValueError) as exc_info:
InferenceEnvInfo.from_slug(
"mlcpuv1", namespace="ociodscdev", bucketname="service-conda-packs"
)
error_message = str(exc_info.value)
assert (
"service conda environment list could not be extracted" in error_message
)
assert (
"full conda environment path from Environment Explorer" in error_message
)

@patch("ads.model.runtime.env_info.get_service_packs")
@patch("ads.model.runtime.env_info.utils.is_path_exists", return_value=True)
Expand Down Expand Up @@ -390,6 +408,23 @@ def test_from_path(
mock_get_service_packs.assert_not_called()
mock_fetch_metadata.assert_called_once()

@patch("ads.model.runtime.env_info.get_service_packs")
@patch("ads.model.runtime.env_info.utils.is_path_exists", return_value=False)
def test_from_path_not_accessible(self, _mock_is_path_exists, mock_get_service_packs):
env_path = "oci://license_checker@ociodscdev/conda/missing"
with pytest.raises(ValueError) as exc_info:
InferenceEnvInfo.from_path(env_path, auth={"signer": object()})
error_message = str(exc_info.value)
assert f"conda environment path `{env_path}`" in error_message
assert "does not exist or is not accessible" in error_message
assert (
"valid full conda environment path from Environment Explorer"
in error_message
)
assert "service conda environment list" not in error_message
assert "conda environment slug" not in error_message
mock_get_service_packs.assert_not_called()

def test_from_dict(self):
info = InferenceEnvInfo.from_dict(
self.runtime_dict["MODEL_DEPLOYMENT"]["INFERENCE_CONDA_ENV"]
Expand Down
Loading