diff --git a/tests/unitary/with_extras/model/test_env_info.py b/tests/unitary/with_extras/model/test_env_info.py index 41fd31574..ce1695283 100644 --- a/tests/unitary/with_extras/model/test_env_info.py +++ b/tests/unitary/with_extras/model/test_env_info.py @@ -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) @@ -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): @@ -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) @@ -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"]