Skip to content

Commit 14c54c4

Browse files
committed
FIX make backport of assert_raises_regex raise the same error as the python3 version.
1 parent 8ecfa3c commit 14c54c4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

sklearn/utils/testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def assert_raises_regex(expected_exception, expected_regexp,
8888
"%r. %r does not." %
8989
(expected_regexp, error_message))
9090
if not_raised:
91-
raise AssertionError("Should have raised %r" %
92-
expected_exception(expected_regexp))
91+
raise AssertionError("%s not raised by %s" %
92+
(expected_exception.__name__, callable_obj.__name__))
9393

9494
# assert_raises_regexp is deprecated in Python 3.4 in favor of
9595
# assert_raises_regex but lets keep the bacward compat in scikit-learn with

sklearn/utils/tests/test_estimator_checks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def test_check_estimator():
4747
msg = "object has no attribute 'fit'"
4848
assert_raises_regex(AttributeError, msg, check_estimator, BaseEstimator)
4949
# check that fit does input validation
50-
msg = "argument must be a string or a number"
50+
msg = "TypeError not raised by fit"
5151
assert_raises_regex(AssertionError, msg, check_estimator, BaseBadClassifier)
52-
# check that predict does input validation
52+
# check that predict does input validation (doesn't accept dicts in input)
5353
msg = "Estimator doesn't check for NaN and inf in predict"
5454
assert_raises_regex(AssertionError, msg, check_estimator, NoCheckinPredict)
5555
# check for sparse matrix input handling

0 commit comments

Comments
 (0)