def test_test_no_score(self, test): dataset_loader_test, model_persister = Mock(), Mock() X, y = object(), object() dataset_loader_test.return_value = X, y model_persister.read.return_value = Mock(spec=['fit', 'predict']) model_persister.read.return_value.__metadata__ = {'version': 99} with pytest.raises(ValueError): test(dataset_loader_test, model_persister)
def test_test(self, test): dataset_loader_test, model_persister = Mock(), Mock() X, y = object(), object() dataset_loader_test.return_value = X, y model = model_persister.read.return_value model.__metadata__ = {'version': 77} test(dataset_loader_test, model_persister, model_version=77) dataset_loader_test.assert_called_with() model_persister.read.assert_called_with(version=77) model.score.assert_called_with(X, y)
def test_test_two_scores(self, test): dataset_loader_test, model_persister, scorer = Mock(), Mock(), Mock() X, y = object(), object() dataset_loader_test.return_value = X, y model = model_persister.read.return_value model.__metadata__ = {'version': 77} test(dataset_loader_test, model_persister, scoring=scorer, model_version=77) dataset_loader_test.assert_called_with() model_persister.read.assert_called_with(version=77) scorer.assert_called_with(model, X, y) assert model.score.call_count == 0
def test_scoring_dict(self, test): dataset_loader_test, model_persister = Mock(), Mock() scoring = {'AUC': Mock(), 'accuracy': Mock()} scoring['AUC'].return_value = 1.23 scoring['accuracy'].return_value = 3.45 X, y = object(), object() dataset_loader_test.return_value = X, y model = model_persister.read.return_value model.__metadata__ = {'version': 77} result = test(dataset_loader_test, model_persister, scoring=scoring, model_version=77) scoring['AUC'].assert_called_with(model, X, y) scoring['accuracy'].assert_called_with(model, X, y) assert sorted(result) == ['AUC: 1.23', 'accuracy: 3.45']