@@ -66,14 +66,31 @@ def test_predict_monotonous(estimator, build_dataset,
6666 ids = ids_pairs_learners )
6767def test_raise_not_fitted_error_if_not_fitted (estimator , build_dataset ,
6868 with_preprocessor ):
69- """Test that a NotFittedError is raised if someone tries to predict and
70- the metric learner has not been fitted."""
69+ """Test that a NotFittedError is raised if someone tries to use
70+ score_pairs, decision_function, get_metric, transform or
71+ get_mahalanobis_matrix on input data and the metric learner
72+ has not been fitted."""
7173 input_data , labels , preprocessor , _ = build_dataset (with_preprocessor )
7274 estimator = clone (estimator )
7375 estimator .set_params (preprocessor = preprocessor )
7476 set_random_state (estimator )
77+ with pytest .raises (NotFittedError ):
78+ estimator .score_pairs (input_data )
7579 with pytest .raises (NotFittedError ):
7680 estimator .decision_function (input_data )
81+ with pytest .raises (NotFittedError ):
82+ estimator .get_metric ()
83+ with pytest .raises (NotFittedError ):
84+ estimator .transform (input_data )
85+ with pytest .raises (NotFittedError ):
86+ estimator .get_mahalanobis_matrix ()
87+ with pytest .raises (NotFittedError ):
88+ estimator .calibrate_threshold (input_data , labels )
89+
90+ with pytest .raises (NotFittedError ):
91+ estimator .set_threshold (0.5 )
92+ with pytest .raises (NotFittedError ):
93+ estimator .predict (input_data )
7794
7895
7996@pytest .mark .parametrize ('calibration_params' ,
@@ -138,15 +155,16 @@ def fit(self, pairs, y):
138155
139156
140157def test_unset_threshold ():
141- # test that set_threshold indeed sets the threshold
158+ """Tests that the "threshold is unset" error is raised when using predict
159+ (performs binary classification on pairs) with an unset threshold."""
142160 identity_pairs_classifier = IdentityPairsClassifier ()
143161 pairs = np .array ([[[0. ], [1. ]], [[1. ], [3. ]], [[2. ], [5. ]], [[3. ], [7. ]]])
144162 y = np .array ([1 , 1 , - 1 , - 1 ])
145163 identity_pairs_classifier .fit (pairs , y )
146164 with pytest .raises (AttributeError ) as e :
147165 identity_pairs_classifier .predict (pairs )
148166
149- expected_msg = ("A threshold for this estimator has not been set,"
167+ expected_msg = ("A threshold for this estimator has not been set, "
150168 "call its set_threshold or calibrate_threshold method." )
151169
152170 assert str (e .value ) == expected_msg
@@ -362,6 +380,7 @@ class MockBadPairsClassifier(MahalanobisMixin, _PairsClassifierMixin):
362380 """
363381
364382 def fit (self , pairs , y , calibration_params = None ):
383+ self .preprocessor_ = 'not used'
365384 self .components_ = 'not used'
366385 self .calibrate_threshold (pairs , y , ** (calibration_params if
367386 calibration_params is not None else
0 commit comments