TST remove assert_warns in feature_extraction/tests/ module
@@ -29,8 +29,7 @@ from numpy.testing import assert_array_almost_equal
from numpy.testing import assert_array_equal
from sklearn.utils import IS_PYPY
from sklearn.utils._testing import (assert_almost_equal,
- assert_warns_message, assert_raise_message,
- assert_no_warnings,
+ assert_raise_message,
fails_if_pypy,
assert_allclose_dense_sparse,
skip_if_32bit)
@@ -386,8 +385,8 @@ def test_countvectorizer_uppercase_in_vocab():
" be matched with any documents")
vectorizer = CountVectorizer(lowercase=True, vocabulary=vocabulary)
- assert_warns_message(UserWarning, message,
- vectorizer.fit_transform, vocabulary)
+ with pytest.warns(UserWarning, match=message):
+ vectorizer.fit_transform(vocabulary)
def test_tf_idf_smoothing():
@@ -429,8 +428,8 @@ def test_tfidf_no_smoothing():
tr = TfidfTransformer(smooth_idf=False, norm='l2')
in_warning_message = 'divide by zero'
- assert_warns_message(RuntimeWarning, in_warning_message,
- tr.fit_transform, X).toarray()
+ with pytest.warns(RuntimeWarning, match=in_warning_message):
+ tr.fit_transform(X).toarray()
def test_sublinear_tf():
@@ -1213,27 +1212,29 @@ def _check_stop_words_consistency(estimator):
@fails_if_pypy
def test_vectorizer_stop_words_inconsistent():
- lstr = "['and', 'll', 've']"
+ lstr = r"\['and', 'll', 've'\]"
message = ('Your stop_words may be inconsistent with your '
'preprocessing. Tokenizing the stop words generated '
'tokens %s not in stop_words.' % lstr)
for vec in [CountVectorizer(),
TfidfVectorizer(), HashingVectorizer()]:
vec.set_params(stop_words=["you've", "you", "you'll", 'AND'])
- assert_warns_message(UserWarning, message, vec.fit_transform,
- ['hello world'])
+ with pytest.warns(UserWarning, match=message):
+ vec.fit_transform(['hello world'])
# reset stop word validation
del vec._stop_words_id
assert _check_stop_words_consistency(vec) is False
# Only one warning per stop list
- assert_no_warnings(vec.fit_transform, ['hello world'])
+ with pytest.warns(None) as record:
+ vec.fit_transform(['hello world'])
+ assert not len(record)
assert _check_stop_words_consistency(vec) is None
# Test caching of inconsistency assessment
vec.set_params(stop_words=["you've", "you", "you'll", 'blah', 'AND'])
- assert_warns_message(UserWarning, message, vec.fit_transform,
- ['hello world'])
+ with pytest.warns(UserWarning, match=message):
+ vec.fit_transform(['hello world'])
@skip_if_32bit
