Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions sklearn/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import sklearn
from sklearn.utils._testing import assert_array_equal
from sklearn.utils._testing import assert_raises
from sklearn.utils._testing import assert_no_warnings
from sklearn.utils._testing import assert_warns_message
from sklearn.utils._testing import ignore_warnings
Expand Down Expand Up @@ -145,16 +144,20 @@ def test_clone_buggy():
# Check that clone raises an error on buggy estimators.
buggy = Buggy()
buggy.a = 2
assert_raises(RuntimeError, clone, buggy)
with pytest.raises(RuntimeError):
clone(buggy)

no_estimator = NoEstimator()
assert_raises(TypeError, clone, no_estimator)
with pytest.raises(TypeError):
clone(no_estimator)

varg_est = VargEstimator()
assert_raises(RuntimeError, clone, varg_est)
with pytest.raises(RuntimeError):
clone(varg_est)

est = ModifyInitParams()
assert_raises(RuntimeError, clone, est)
with pytest.raises(RuntimeError):
clone(est)


def test_clone_empty_array():
Expand Down Expand Up @@ -233,7 +236,9 @@ def test_get_params():

test.set_params(a__d=2)
assert test.a.d == 2
assert_raises(ValueError, test.set_params, a__a=2)

with pytest.raises(ValueError):
test.set_params(a__a=2)


def test_is_classifier():
Expand All @@ -248,10 +253,15 @@ def test_is_classifier():
def test_set_params():
# test nested estimator parameter setting
clf = Pipeline([("svc", SVC())])

# non-existing parameter in svc
assert_raises(ValueError, clf.set_params, svc__stupid_param=True)
with pytest.raises(ValueError):
clf.set_params(svc__stupid_param=True)

# non-existing parameter of pipeline
assert_raises(ValueError, clf.set_params, svm__stupid_param=True)
with pytest.raises(ValueError):
clf.set_params(svm__stupid_param=True)

# we don't currently catch if the things in pipeline are estimators
# bad_pipeline = Pipeline([("bad", NoEstimator())])
# assert_raises(AttributeError, bad_pipeline.set_params,
Expand Down