def test_experiment_client_create_name_conflict(mocker): error_code = "experiment_name_conflict" exception = Conflict(mocker.Mock(), mocker.Mock(), error_code) mocker.patch.object(ExperimentClient, "_post", side_effect=exception) client = ExperimentClient(mocker.Mock(), mocker.Mock()) with pytest.raises(ExperimentNameConflict, match="name 'experiment name' already exists"): client.create(PROJECT_ID, "experiment name")
def test_experiment_client_update_name_conflict(mocker): error_code = "experiment_name_conflict" exception = Conflict(mocker.Mock(), mocker.Mock(), error_code) mocker.patch.object(ExperimentClient, "_patch_raw", side_effect=exception) client = ExperimentClient(mocker.Mock(), mocker.Mock()) with pytest.raises(ExperimentNameConflict, match="name 'new name' already exists"): client.update(PROJECT_ID, EXPERIMENT_ID, name="new name")
def test_log_run_data_other_conflict(mocker): response_mock = mocker.Mock() exception = Conflict(response_mock, "", "") mocker.patch.object(ExperimentClient, "_patch_raw", side_effect=exception) client = ExperimentClient(mocker.Mock(), mocker.Mock()) with pytest.raises(Conflict): client.log_run_data(PROJECT_ID, EXPERIMENT_RUN_ID, params=[mocker.Mock()])
def test_object_client_create_directory_already_exists(mocker): error_code = "object_already_exists" exception = Conflict(mocker.Mock(), mocker.Mock(), error_code) mocker.patch.object(ObjectClient, "_put_raw", side_effect=exception) client = ObjectClient(mocker.Mock(), mocker.Mock()) with pytest.raises(PathAlreadyExists, match="'test-path' already exists"): client.create_directory(PROJECT_ID, "test-path") ObjectClient._put_raw.assert_called_once_with( "/project/{}/directory/{}".format(PROJECT_ID, "test-path"), params={"parents": 0}, )
def test_log_run_data_param_conflict(mocker): message = "bad params" error_code = "conflicting_params" response_mock = mocker.Mock() response_mock.json.return_value = {"parameterKeys": ["bad-key"]} exception = Conflict(response_mock, message, error_code) mocker.patch.object(ExperimentClient, "_patch_raw", side_effect=exception) client = ExperimentClient(mocker.Mock(), mocker.Mock()) with pytest.raises(ParamConflict, match=message): client.log_run_data(PROJECT_ID, EXPERIMENT_RUN_ID, params=[mocker.Mock()])
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(), 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(), )