11
11
import time
12
12
13
13
import numpy as np
14
- from sklearn .utils .testing import assert_raise_message
15
14
from sklearn .utils .testing import assert_array_equal
16
15
from sklearn .utils .testing import assert_array_almost_equal
17
16
from sklearn .utils .testing import assert_allclose
@@ -266,11 +265,8 @@ def test_pipeline_fit_params():
266
265
assert pipe .named_steps ['transf' ].a is None
267
266
assert pipe .named_steps ['transf' ].b is None
268
267
# invalid parameters should raise an error message
269
- assert_raise_message (
270
- TypeError ,
271
- "fit() got an unexpected keyword argument 'bad'" ,
272
- pipe .fit , None , None , clf__bad = True
273
- )
268
+ with raises (TypeError , match = "unexpected keyword argument" ):
269
+ pipe .fit (None , None , clf__bad = True )
274
270
275
271
276
272
def test_pipeline_sample_weight_supported ():
@@ -291,32 +287,19 @@ def test_pipeline_sample_weight_unsupported():
291
287
pipe .fit (X , y = None )
292
288
assert pipe .score (X ) == 3
293
289
assert pipe .score (X , sample_weight = None ) == 3
294
- assert_raise_message (
295
- TypeError ,
296
- "score() got an unexpected keyword argument 'sample_weight'" ,
297
- pipe .score , X , sample_weight = np .array ([2 , 3 ])
298
- )
290
+ with raises (TypeError , match = "unexpected keyword argument" ):
291
+ pipe .score (X , sample_weight = np .array ([2 , 3 ]))
299
292
300
293
301
294
def test_pipeline_raise_set_params_error ():
302
295
# Test pipeline raises set params error message for nested models.
303
296
pipe = Pipeline ([('cls' , LinearRegression ())])
304
-
305
- # expected error message
306
- error_msg = ('Invalid parameter %s for estimator %s. '
307
- 'Check the list of available parameters '
308
- 'with `estimator.get_params().keys()`.' )
309
-
310
- assert_raise_message (ValueError ,
311
- error_msg % ('fake' , 'Pipeline' ),
312
- pipe .set_params ,
313
- fake = 'nope' )
297
+ with raises (ValueError , match = "Invalid parameter" ):
298
+ pipe .set_params (fake = 'nope' )
314
299
315
300
# nested model check
316
- assert_raise_message (ValueError ,
317
- error_msg % ("fake" , pipe ),
318
- pipe .set_params ,
319
- fake__estimator = 'nope' )
301
+ with raises (ValueError , match = "Invalid parameter" ):
302
+ pipe .set_params (fake__estimator = 'nope' )
320
303
321
304
322
305
def test_pipeline_methods_pca_svm ():
@@ -537,9 +520,8 @@ def make():
537
520
assert_array_equal ([[exp ]], pipeline .fit (X , y ).transform (X ))
538
521
assert_array_equal ([[exp ]], pipeline .fit_transform (X , y ))
539
522
assert_array_equal (X , pipeline .inverse_transform ([[exp ]]))
540
- assert_raise_message (AttributeError ,
541
- "'NoneType' object has no attribute 'predict'" ,
542
- getattr , pipeline , 'predict' )
523
+ with raises (AttributeError , match = "has no attribute 'predict'" ):
524
+ getattr (pipeline , 'predict' )
543
525
544
526
# Check None step at construction time
545
527
exp = 2 * 5
0 commit comments