def test_experiment_create_run_experiment_deleted_conflict(mocker): message = "experiment deleted" error_code = "experiment_deleted" response_mock = mocker.Mock() response_mock.json.return_value = {"experimentId": 42} exception = Conflict(response_mock, message, error_code) mocker.patch.object(ExperimentClient, "_post", side_effect=exception) client = ExperimentClient(mocker.Mock()) with pytest.raises(ExperimentDeleted, match=message): client.create_run( PROJECT_ID, EXPERIMENT_ID, name=mocker.Mock(), started_at=mocker.Mock(), parent_run_id=PARENT_RUN_ID, artifact_location=mocker.Mock(), )
def test_experiment_create_run(mocker): run = mocker.Mock() mocker.patch.object(ExperimentClient, "_post", return_value=run) request_schema_mock = mocker.patch( "faculty.clients.experiment._client.CreateRunSchema" ) dump_mock = request_schema_mock.return_value.dump response_schema_mock = mocker.patch( "faculty.clients.experiment._client.ExperimentRunSchema" ) run_name = mocker.Mock() started_at = mocker.Mock() artifact_location = mocker.Mock() client = ExperimentClient(mocker.Mock()) returned_run = client.create_run( PROJECT_ID, EXPERIMENT_ID, run_name, started_at, PARENT_RUN_ID, artifact_location=artifact_location, ) assert returned_run == run request_schema_mock.assert_called_once_with() dump_mock.assert_called_once_with( { "name": run_name, "parent_run_id": PARENT_RUN_ID, "started_at": started_at, "artifact_location": artifact_location, "tags": [], } ) response_schema_mock.assert_called_once_with() ExperimentClient._post.assert_called_once_with( "/project/{}/experiment/{}/run".format(PROJECT_ID, EXPERIMENT_ID), response_schema_mock.return_value, json=dump_mock.return_value, )