@@ -232,13 +232,13 @@ def test_regressor_modifications(self):
232232 # kernel parameters now inconsistent
233233 with self .assertRaises (ValueError ) as cm :
234234 kpcovr .fit (self .X , self .Y )
235- self .assertTrue (
236- str (cm .message ),
237- "Kernel parameter mismatch: the regressor has kernel parameters "
238- "{kernel: linear, gamma: 0.2, degree: 3, coef0: 1, kernel_params: None}"
239- " and KernelPCovR was initialized with kernel parameters "
240- "{kernel: linear, gamma: 0.1, degree: 3, coef0: 1, kernel_params: None}" ,
241- )
235+ self .assertTrue (
236+ str (cm .exception ),
237+ "Kernel parameter mismatch: the regressor has kernel parameters "
238+ "{kernel: linear, gamma: 0.2, degree: 3, coef0: 1, kernel_params: None}"
239+ " and KernelPCovR was initialized with kernel parameters "
240+ "{kernel: linear, gamma: 0.1, degree: 3, coef0: 1, kernel_params: None}" ,
241+ )
242242
243243 def test_incompatible_regressor (self ):
244244 regressor = Ridge (alpha = 1e-8 )
@@ -247,10 +247,10 @@ def test_incompatible_regressor(self):
247247
248248 with self .assertRaises (ValueError ) as cm :
249249 kpcovr .fit (self .X , self .Y )
250- self .assertTrue (
251- str (cm .message ),
252- "Regressor must be an instance of `KernelRidge`" ,
253- )
250+ self .assertTrue (
251+ str (cm .exception ),
252+ "Regressor must be an instance of `KernelRidge`" ,
253+ )
254254
255255 def test_none_regressor (self ):
256256 kpcovr = KernelPCovR (mixing = 0.5 , regressor = None )
@@ -269,24 +269,24 @@ def test_incompatible_coef_shape(self):
269269 # Dimension mismatch
270270 with self .assertRaises (ValueError ) as cm :
271271 kpcovr .fit (self .X , self .Y [:, 0 ])
272- self .assertTrue (
273- str (cm .message ),
274- "The regressor coefficients have a dimension incompatible "
275- "with the supplied target space. "
276- "The coefficients have dimension %d and the targets "
277- "have dimension %d" % (regressor .dual_coef_ .ndim , self .Y [:, 0 ].ndim ),
278- )
272+ self .assertTrue (
273+ str (cm .exception ),
274+ "The regressor coefficients have a dimension incompatible "
275+ "with the supplied target space. "
276+ "The coefficients have dimension %d and the targets "
277+ "have dimension %d" % (regressor .dual_coef_ .ndim , self .Y [:, 0 ].ndim ),
278+ )
279279
280280 # Shape mismatch (number of targets)
281281 with self .assertRaises (ValueError ) as cm :
282282 kpcovr .fit (self .X , self .Y )
283- self .assertTrue (
284- str (cm .message ),
285- "The regressor coefficients have a shape incompatible "
286- "with the supplied target space. "
287- "The coefficients have shape %r and the targets "
288- "have shape %r" % (regressor .dual_coef_ .shape , self .Y .shape ),
289- )
283+ self .assertTrue (
284+ str (cm .exception ),
285+ "The regressor coefficients have a shape incompatible "
286+ "with the supplied target space. "
287+ "The coefficients have shape %r and the targets "
288+ "have shape %r" % (regressor .dual_coef_ .shape , self .Y .shape ),
289+ )
290290
291291 def test_precomputed_regression (self ):
292292 regressor = KernelRidge (alpha = 1e-8 , kernel = "rbf" , gamma = 0.1 )
@@ -422,7 +422,7 @@ def test_bad_solver(self):
422422 kpcovr = self .model (svd_solver = "bad" )
423423 kpcovr .fit (self .X , self .Y )
424424
425- self .assertTrue (str (cm .message ), "Unrecognized svd_solver='bad'" "" )
425+ self .assertTrue (str (cm .exception ), "Unrecognized svd_solver='bad'" "" )
426426
427427 def test_good_n_components (self ):
428428 """
@@ -454,60 +454,60 @@ def test_bad_n_components(self):
454454 kpcovr = self .model (n_components = - 1 , svd_solver = "auto" )
455455 kpcovr .fit (self .X , self .Y )
456456
457- self .assertTrue (
458- str (cm .message ),
459- "self.n_components=%r must be between 0 and "
460- "min(n_samples, n_features)=%r with "
461- "svd_solver='%s'"
462- % (
463- kpcovr .n_components ,
464- self .X .shape [0 ],
465- kpcovr .svd_solver ,
466- ),
467- )
457+ self .assertTrue (
458+ str (cm .exception ),
459+ "self.n_components=%r must be between 0 and "
460+ "min(n_samples, n_features)=%r with "
461+ "svd_solver='%s'"
462+ % (
463+ kpcovr .n_components ,
464+ self .X .shape [0 ],
465+ kpcovr .svd_solver ,
466+ ),
467+ )
468468 with self .subTest (type = "0_ncomponents" ):
469469 with self .assertRaises (ValueError ) as cm :
470470 kpcovr = self .model (n_components = 0 , svd_solver = "randomized" )
471471 kpcovr .fit (self .X , self .Y )
472472
473- self .assertTrue (
474- str (cm .message ),
475- "self.n_components=%r must be between 1 and "
476- "min(n_samples, n_features)=%r with "
477- "svd_solver='%s'"
478- % (
479- kpcovr .n_components ,
480- self .X .shape [0 ],
481- kpcovr .svd_solver ,
482- ),
483- )
473+ self .assertTrue (
474+ str (cm .exception ),
475+ "self.n_components=%r must be between 1 and "
476+ "min(n_samples, n_features)=%r with "
477+ "svd_solver='%s'"
478+ % (
479+ kpcovr .n_components ,
480+ self .X .shape [0 ],
481+ kpcovr .svd_solver ,
482+ ),
483+ )
484484 with self .subTest (type = "arpack_X_ncomponents" ):
485485 with self .assertRaises (ValueError ) as cm :
486486 kpcovr = self .model (n_components = self .X .shape [0 ], svd_solver = "arpack" )
487487 kpcovr .fit (self .X , self .Y )
488- self .assertTrue (
489- str (cm .message ),
490- "self.n_components=%r must be strictly less than "
491- "min(n_samples, n_features)=%r with "
492- "svd_solver='%s'"
493- % (
494- kpcovr .n_components ,
495- self .X .shape [0 ],
496- kpcovr .svd_solver ,
497- ),
498- )
488+ self .assertTrue (
489+ str (cm .exception ),
490+ "self.n_components=%r must be strictly less than "
491+ "min(n_samples, n_features)=%r with "
492+ "svd_solver='%s'"
493+ % (
494+ kpcovr .n_components ,
495+ self .X .shape [0 ],
496+ kpcovr .svd_solver ,
497+ ),
498+ )
499499
500500 for svd_solver in ["auto" , "full" ]:
501501 with self .subTest (type = "pi_ncomponents" ):
502502 with self .assertRaises (ValueError ) as cm :
503503 kpcovr = self .model (n_components = np .pi , svd_solver = svd_solver )
504504 kpcovr .fit (self .X , self .Y )
505- self .assertTrue (
506- str (cm .message ),
507- "self.n_components=%r must be of type int "
508- "when greater than or equal to 1, was of type=%r"
509- % (kpcovr .n_components , type (kpcovr .n_components )),
510- )
505+ self .assertTrue (
506+ str (cm .exception ),
507+ "self.n_components=%r must be of type int "
508+ "when greater than or equal to 1, was of type=%r"
509+ % (kpcovr .n_components , type (kpcovr .n_components )),
510+ )
511511
512512
513513if __name__ == "__main__" :
0 commit comments