@@ -110,14 +110,14 @@ def test_reconstruction_errors(kpcovc_model, X, Y, error_tol):
110110def test_nonfitted_failure (X ):
111111 kpcovc = KernelPCovC (mixing = 0.5 , n_components = 4 , tol = 1e-12 )
112112 with pytest .raises (exceptions .NotFittedError ):
113- _ = kpcovc .transform (X )
113+ kpcovc .transform (X )
114114
115115
116116def test_no_arg_predict (X , Y ):
117117 kpcovc = KernelPCovC (mixing = 0.5 , n_components = 4 , tol = 1e-12 )
118118 kpcovc .fit (X , Y )
119119 with pytest .raises (ValueError ):
120- _ = kpcovc .predict ()
120+ kpcovc .predict ()
121121
122122
123123def test_T_shape (X , Y ):
@@ -145,28 +145,30 @@ def test_Z_shape(kpcovc_model, X, Y):
145145def test_decision_function (kpcovc_model , X , Y ):
146146 kpcovc = kpcovc_model (center = True )
147147 kpcovc .fit (X , Y )
148- with pytest .raises (ValueError ) as cm :
149- _ = kpcovc .decision_function ()
150- assert str (cm .value ) == "Either X or T must be supplied."
151- _ = kpcovc .decision_function (X )
148+
149+ with pytest .raises (ValueError , match = "Either X or T must be supplied." ):
150+ kpcovc .decision_function ()
151+
152+ kpcovc .decision_function (X )
152153 T = kpcovc .transform (X )
153- _ = kpcovc .decision_function (T = T )
154+ kpcovc .decision_function (T = T )
154155
155156
156157def test_no_centerer (kpcovc_model , X , Y ):
157158 kpcovc = kpcovc_model (center = False )
158159 kpcovc .fit (X , Y )
159160 with pytest .raises (AttributeError ):
160- _ = kpcovc .centerer_
161+ kpcovc .centerer_
161162
162163
163164def test_centerer (kpcovc_model , X , Y ):
164165 kpcovc = kpcovc_model (center = True )
165166 kpcovc .fit (X , Y )
166167 assert hasattr (kpcovc , "centerer_" )
167- _ = kpcovc .predict (X )
168- _ = kpcovc .transform (X )
169- _ = kpcovc .score (X , Y )
168+
169+ kpcovc .predict (X )
170+ kpcovc .transform (X )
171+ kpcovc .score (X , Y )
170172
171173
172174def test_prefit_classifier (X , Y ):
@@ -198,14 +200,14 @@ def test_incompatible_classifier(kpcovc_model, X, Y):
198200 classifier = GaussianNB ()
199201 classifier .fit (X , Y )
200202 kpcovc = kpcovc_model (mixing = 0.5 , classifier = classifier )
201- with pytest .raises (ValueError ) as cm :
202- kpcovc .fit (X , Y )
203- assert str (cm .value ) == (
203+ expected_msg = (
204204 "Classifier must be an instance of "
205205 "`LogisticRegression`, `LogisticRegressionCV`, `LinearSVC`, "
206206 "`LinearDiscriminantAnalysis`, `RidgeClassifier`, `RidgeClassifierCV`, "
207207 "`SGDClassifier`, `Perceptron`, or `precomputed`"
208208 )
209+ with pytest .raises (ValueError , match = expected_msg ):
210+ kpcovc .fit (X , Y )
209211
210212
211213def test_none_classifier (X , Y ):
@@ -221,15 +223,13 @@ def test_incompatible_coef_shape(kpcovc_model, X, Y):
221223 cl_multi = LinearSVC ()
222224 cl_multi .fit (K , np .random .randint (0 , 3 , size = X .shape [0 ]))
223225 kpcovc_binary = kpcovc_model (mixing = 0.5 , classifier = cl_multi )
224- with pytest .raises (ValueError ) as cm :
226+ with pytest .raises (ValueError , match = "For binary classification" ) :
225227 kpcovc_binary .fit (X , Y )
226- assert "For binary classification" in str (cm .value )
227228 cl_binary = LinearSVC ()
228229 cl_binary .fit (K , Y )
229230 kpcovc_multi = kpcovc_model (mixing = 0.5 , classifier = cl_binary )
230- with pytest .raises (ValueError ) as cm :
231+ with pytest .raises (ValueError , match = "For multiclass classification" ) :
231232 kpcovc_multi .fit (X , np .random .randint (0 , 3 , size = X .shape [0 ]))
232- assert "For multiclass classification" in str (cm .value )
233233
234234
235235def test_precomputed_classification (X , Y , error_tol ):
@@ -327,10 +327,9 @@ def test_svd_solvers(kpcovc_model, X, Y):
327327
328328
329329def test_bad_solver (kpcovc_model , X , Y ):
330- with pytest .raises (ValueError ) as cm :
330+ with pytest .raises (ValueError , match = "Unrecognized svd_solver='bad'" ) :
331331 kpcovc = kpcovc_model (svd_solver = "bad" )
332332 kpcovc .fit (X , Y )
333- assert str (cm .value ) == "Unrecognized svd_solver='bad'"
334333
335334
336335def test_good_n_components (kpcovc_model , X , Y ):
@@ -344,20 +343,16 @@ def test_good_n_components(kpcovc_model, X, Y):
344343
345344
346345def test_bad_n_components (kpcovc_model , X , Y ):
347- with pytest .raises (ValueError ) as cm :
346+ with pytest .raises (ValueError , match = "n_components=" ) :
348347 kpcovc = kpcovc_model (n_components = - 1 , svd_solver = "auto" )
349348 kpcovc .fit (X , Y )
350- assert str (cm .value ).startswith ("n_components=" )
351- with pytest .raises (ValueError ) as cm :
349+ with pytest .raises (ValueError , match = "n_components=" ):
352350 kpcovc = kpcovc_model (n_components = 0 , svd_solver = "randomized" )
353351 kpcovc .fit (X , Y )
354- assert str (cm .value ).startswith ("n_components=" )
355- with pytest .raises (ValueError ) as cm :
352+ with pytest .raises (ValueError , match = "n_components=" ):
356353 kpcovc = kpcovc_model (n_components = X .shape [0 ], svd_solver = "arpack" )
357354 kpcovc .fit (X , Y )
358- assert str (cm .value ).startswith ("n_components=" )
359355 for svd_solver in ["auto" , "full" ]:
360- with pytest .raises (ValueError ) as cm :
356+ with pytest .raises (ValueError , match = "must be of type int" ) :
361357 kpcovc = kpcovc_model (n_components = np .pi , svd_solver = svd_solver )
362358 kpcovc .fit (X , Y )
363- assert "must be of type int" in str (cm .value )
0 commit comments