Skip to content

Commit bcde594

Browse files
author
Stephen Hoover
committed
TST Fix test_model to avoid warnings
The tests in `test_model.py` were sending warnings in a few places. Modify the tests so that where we expect a warning, we actually test for it, and where we don't expect a warning, we use a mock metadata object which contains the expected keys.
1 parent fc5b8e4 commit bcde594

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

civis/ml/tests/test_model.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,15 @@ def metadata(self):
226226
raise self.__exc('What a spectacular failure, you say!')
227227

228228
# exception types get caught!
229-
for exc in [FileNotFoundError, CivisJobFailure, KeyError, CancelledError]:
229+
for exc in [FileNotFoundError, CivisJobFailure, CancelledError]:
230230
fut = ModelFutureRaiseExc(exc, 1, 2, client=mock_client)
231231
_model.ModelFuture._set_model_exception(fut)
232232

233+
with pytest.warns(UserWarning):
234+
# The KeyError is caught, but sends a warning
235+
fut = ModelFutureRaiseExc(KeyError, 1, 2, client=mock_client)
236+
_model.ModelFuture._set_model_exception(fut)
237+
233238
fut = ModelFutureRaiseExc(RuntimeError, 1, 2, client=mock_client)
234239
with pytest.raises(RuntimeError):
235240
_model.ModelFuture._set_model_exception(fut)
@@ -421,7 +426,8 @@ def poller(*args, **kwargs):
421426
mock_client.scripts.get_containers_runs = poller
422427

423428
path = '/green/eggs/and/ham'
424-
training_meta = {'run': {'configuration': {'data': {'location': path}}}}
429+
training_meta = {'run': {'configuration': {'data': {'location': path}},
430+
'status': 'succeeded'}}
425431
mock_cio.file_to_json.return_value = training_meta
426432

427433
mf = _model.ModelFuture(job_id=1, run_id=2, train_job_id=11,
@@ -496,7 +502,9 @@ def test_validation_metadata_prediction(mock_spe, mock_f2f,
496502

497503
@mock.patch.object(_model.cio, "file_id_from_run_output", autospec=True)
498504
@mock.patch.object(_model.cio, "file_to_json",
499-
mock.MagicMock(return_value={'metrics': 'foo'}))
505+
mock.MagicMock(
506+
return_value={'metrics': 'foo',
507+
'run': {'status': 'succeeded'}}))
500508
def test_metrics_training(mock_file_id_from_run_output):
501509
mock_file_id_from_run_output.return_value = 11
502510
c = setup_client_mock(3, 7)
@@ -509,7 +517,9 @@ def test_metrics_training(mock_file_id_from_run_output):
509517

510518
@mock.patch.object(_model.cio, "file_id_from_run_output", autospec=True)
511519
@mock.patch.object(_model.cio, "file_to_json",
512-
mock.MagicMock(return_value={'metrics': 'foo'}))
520+
mock.MagicMock(
521+
return_value={'metrics': 'foo',
522+
'run': {'status': 'succeeded'}}))
513523
def test_metrics_prediction(mock_file_id_from_run_output):
514524
mock_file_id_from_run_output.return_value = 11
515525
c = setup_client_mock(3, 7)

0 commit comments

Comments
 (0)