def test_log_run_data_empty(mocker): mocker.patch.object(ExperimentClient, "_patch_raw") client = ExperimentClient(mocker.Mock()) client.log_run_data(PROJECT_ID, EXPERIMENT_RUN_ID) ExperimentClient._patch_raw.assert_not_called()
def test_log_run_data(mocker): mocker.patch.object(ExperimentClient, "_patch_raw") run_data_schema_mock = mocker.patch( "faculty.clients.experiment._client.ExperimentRunDataSchema" ) run_data_dump_mock = run_data_schema_mock.return_value.dump metric = mocker.Mock() param = mocker.Mock() tag = mocker.Mock() client = ExperimentClient(mocker.Mock()) client.log_run_data( PROJECT_ID, EXPERIMENT_RUN_ID, metrics=[metric], params=[param], tags=[tag], ) run_data_schema_mock.assert_called_once_with() run_data_dump_mock.assert_called_once_with( {"metrics": [metric], "params": [param], "tags": [tag]} ) ExperimentClient._patch_raw.assert_called_once_with( "/project/{}/run/{}/data".format(PROJECT_ID, EXPERIMENT_RUN_ID), json=run_data_dump_mock.return_value, )
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()) with pytest.raises(Conflict): client.log_run_data( PROJECT_ID, EXPERIMENT_RUN_ID, params=[mocker.Mock()] )
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()) with pytest.raises(ParamConflict, match=message): client.log_run_data( PROJECT_ID, EXPERIMENT_RUN_ID, params=[mocker.Mock()] )