def test_create_run_backwards_compatability( mocker, run_name_tag, expected_run_name, parent_run_id_tag, expected_parent_run_id, ): mocker.patch("mlflow_faculty.tracking.mlflow_timestamp_to_datetime") mocker.patch("mlflow_faculty.tracking.mlflow_tag_to_faculty_tag") mock_client = mocker.Mock() mocker.patch("faculty.client", return_value=mock_client) mocker.patch("mlflow_faculty.tracking.faculty_run_to_mlflow_run") tags = [] if run_name_tag is not None: tags.append(RunTag(key=MLFLOW_RUN_NAME, value=run_name_tag)) if parent_run_id_tag is not None: tags.append(RunTag(key=MLFLOW_PARENT_RUN_ID, value=parent_run_id_tag)) store = FacultyRestStore(STORE_URI) store.create_run( EXPERIMENT_ID, "unused-mlflow-user-id", RUN_STARTED_AT_MILLISECONDS, tags, ) args, _ = mock_client.create_run.call_args assert args[2] == expected_run_name assert args[4] == expected_parent_run_id
def test_create_run_experiment_deleted(mocker): mocker.patch( "mlflow_faculty.tracking.mlflow_timestamp_to_datetime", return_value=mocker.Mock(), ) mocker.patch( "mlflow_faculty.tracking.mlflow_tag_to_faculty_tag", return_value=mocker.Mock(), ) mock_client = mocker.Mock() exception = faculty.clients.experiment.ExperimentDeleted( message="message", experiment_id="test-id") mock_client.create_run.side_effect = exception mocker.patch("faculty.client", return_value=mock_client) store = FacultyRestStore(STORE_URI) with pytest.raises(MlflowException, match="experiment"): store.create_run( EXPERIMENT_ID, "unused-mlflow-user-id", RUN_STARTED_AT_MILLISECONDS, tags=[], )
def test_create_run_invalid_parent_run_id(mocker): mock_client = mocker.Mock() mocker.patch("faculty.client", return_value=mock_client) store = FacultyRestStore(STORE_URI) with pytest.raises(ValueError): store.create_run( EXPERIMENT_ID, "unused-mlflow-user-id", RUN_STARTED_AT_MILLISECONDS, [RunTag(key=MLFLOW_PARENT_RUN_ID, value="invalid-uuid")], )
def test_create_run_invalid_experiment_id(mocker): mock_client = mocker.Mock() mocker.patch("faculty.client", return_value=mock_client) store = FacultyRestStore(STORE_URI) with pytest.raises(ValueError): store.create_run( "invalid-experiment-id", "unused-mlflow-user-id", RUN_STARTED_AT_MILLISECONDS, tags=[], )
def test_create_run_client_error(mocker): mocker.patch("mlflow_faculty.tracking.mlflow_timestamp_to_datetime") mocker.patch("mlflow_faculty.tracking.mlflow_tag_to_faculty_tag") mock_client = mocker.Mock() mock_client.create_run.side_effect = HttpError(mocker.Mock(), "Some error") mocker.patch("faculty.client", return_value=mock_client) store = FacultyRestStore(STORE_URI) with pytest.raises(MlflowException, match="Some error"): store.create_run( EXPERIMENT_ID, "unused-mlflow-user-id", RUN_STARTED_AT_MILLISECONDS, tags=[], )
def test_create_run(mocker): mlflow_timestamp = mocker.Mock() faculty_datetime = mocker.Mock() timestamp_converter_mock = mocker.patch( "mlflow_faculty.tracking.mlflow_timestamp_to_datetime", return_value=faculty_datetime, ) mlflow_tag = mocker.Mock() faculty_tag = mocker.Mock() tag_converter_mock = mocker.patch( "mlflow_faculty.tracking.mlflow_tag_to_faculty_tag", return_value=faculty_tag, ) faculty_run = mocker.Mock() mock_client = mocker.Mock() mock_client.create_run.return_value = faculty_run mocker.patch("faculty.client", return_value=mock_client) mlflow_run = mocker.Mock() run_converter_mock = mocker.patch( "mlflow_faculty.tracking.faculty_run_to_mlflow_run", return_value=mlflow_run, ) store = FacultyRestStore(STORE_URI) returned_run = store.create_run( EXPERIMENT_ID, "unused-mlflow-user-id", mlflow_timestamp, [mlflow_tag] ) timestamp_converter_mock.assert_called_once_with(mlflow_timestamp) tag_converter_mock.assert_called_once_with(mlflow_tag) mock_client.create_run.assert_called_once_with( PROJECT_ID, EXPERIMENT_ID, "", faculty_datetime, None, tags=[faculty_tag], ) run_converter_mock.assert_called_once_with(faculty_run) assert returned_run == mlflow_run