def test_run_should_fail_for_invalid_encoded_fn(self): with self.assertRaises(binascii.Error): mlengine_prediction_summary.run([ "--prediction_path=some/path", "--metric_fn_encoded=invalid_encoded_text", "--metric_keys=a", ])
def test_run_should_fail_if_enc_fn_is_not_callable(self): non_callable_value = 1 fn_enc = base64.b64encode(dill.dumps(non_callable_value)).decode('utf-8') with self.assertRaises(ValueError): mlengine_prediction_summary.run( ["--prediction_path=some/path", "--metric_fn_encoded=" + fn_enc, "--metric_keys=a",] )
def test_run_should_not_fail_with_valid_fn(self, io_mock, pipeline_obj_mock, pipeline_mock): def metric_function(): return 1 fn_enc = base64.b64encode(dill.dumps(metric_function)).decode('utf-8') mlengine_prediction_summary.run( ["--prediction_path=some/path", "--metric_fn_encoded=" + fn_enc, "--metric_keys=a",] ) pipeline_mock.assert_called_once_with([]) pipeline_obj_mock.assert_called_once() io_mock.assert_called_once()
def test_run_without_all_arguments_should_raise_exception(self): with self.assertRaises(SystemExit): mlengine_prediction_summary.run() with self.assertRaises(SystemExit): mlengine_prediction_summary.run( ["--prediction_path=some/path",] ) with self.assertRaises(SystemExit): mlengine_prediction_summary.run( ["--prediction_path=some/path", "--metric_fn_encoded=encoded_text",] )