Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nick863 committed Jun 19, 2024
1 parent f5eb893 commit 901ce3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/promptflow-evals/promptflow/evals/evaluate/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# Authentication constants
AZUREML_OBO_ENABLED = "AZUREML_OBO_ENABLED"
DEFAULT_IDENTITY_CLIENT_ID = "DEFAULT_IDENTITY_CLIENT_ID"
EVALUATION_ARTIFACT = 'instance_results.jsonl'
AzureMLWorkspaceTriad = namedtuple("AzureMLWorkspace", ["subscription_id", "resource_group_name", "workspace_name"])


Expand Down Expand Up @@ -104,6 +103,7 @@ def _get_ml_client(trace_destination: str, **kwargs) -> Tuple[Any, AzureMLWorksp
try:
from azure.ai.ml import MLClient
except (ImportError, ModuleNotFoundError):
LOGGER.error("Unable to import azure-ai-ml, the run will not be logged to azure.")
return AzureMLWorkspaceTriad("", "", ""), None

ws_triad = extract_workspace_triad_from_trace_provider(trace_destination)
Expand Down
14 changes: 13 additions & 1 deletion src/promptflow-evals/tests/evals/unittests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,26 @@ def test_force_cli_client(self):
mock_cli.assert_called_once()

@pytest.mark.parametrize('err_type', [ImportError, ModuleNotFoundError])
def test_ml_client_not_imported(self, err_type):
def test_ml_client_not_imported(self, err_type, caplog):
"""Test import of ml_client if it was notimported."""
logger = logging.getLogger(_utils.__name__)
# All loggers, having promptflow. prefix will have "promptflow" logger
# as a parent. This logger does not propagate the logs and cannot be
# captured by caplog. Here we will skip this logger to capture logs.
logger.parent = logging.root
with patch('builtins.__import__', side_effect=err_type('Mock')):
ws_triade, ml_client = _utils._get_ml_client("www.microsoft.com")
assert ml_client is None
assert ws_triade.subscription_id == ""
assert ws_triade.resource_group_name == ""
assert ws_triade.workspace_name == ""
error_messages = [
lg_rec.message
for lg_rec in caplog.records
if lg_rec.levelno == logging.ERROR and (lg_rec.name in _utils.__name__)
]
assert len(error_messages) == 1
assert "Unable to import azure-ai-ml, the run will not be logged to azure." in error_messages

def test_log_no_ml_client_import(self, caplog):
"""Test logging if MLClient cannot be imported."""
Expand Down

0 comments on commit 901ce3b

Please sign in to comment.