|
5 | 5 | from scipy import sparse
|
6 | 6 |
|
7 | 7 | from sklearn.externals.six.moves import zip
|
8 |
| -from sklearn.utils.testing import assert_raises, assert_raises_regex |
| 8 | +from sklearn.utils.testing import assert_raises, assert_raises_regex, assert_raise_message |
9 | 9 | from sklearn.utils.testing import assert_equal
|
10 | 10 | from sklearn.utils.testing import assert_false
|
11 | 11 | from sklearn.utils.testing import assert_true
|
@@ -165,6 +165,27 @@ def test_pipeline_fit_params():
|
165 | 165 | assert_true(pipe.named_steps['transf'].b is None)
|
166 | 166 |
|
167 | 167 |
|
| 168 | +def test_pipeline_raise_set_params_error(): |
| 169 | + # Test pipeline raises set params error message for nested models. |
| 170 | + pipe = Pipeline([('cls', LinearRegression())]) |
| 171 | + |
| 172 | + # expected error message |
| 173 | + error_msg = ('Invalid parameter %s for estimator %s. ' |
| 174 | + 'Check the list of available parameters ' |
| 175 | + 'with `estimator.get_params().keys()`.' ) |
| 176 | + |
| 177 | + assert_raise_message(ValueError, |
| 178 | + error_msg % ('fake', 'Pipeline'), |
| 179 | + pipe.set_params, |
| 180 | + fake='nope') |
| 181 | + |
| 182 | + # nested model check |
| 183 | + assert_raise_message(ValueError, |
| 184 | + error_msg % ("fake", pipe), |
| 185 | + pipe.set_params, |
| 186 | + fake__estimator='nope') |
| 187 | + |
| 188 | + |
168 | 189 | def test_pipeline_methods_pca_svm():
|
169 | 190 | # Test the various methods of the pipeline (pca + svm).
|
170 | 191 | iris = load_iris()
|
|
0 commit comments