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

Skip to content

Commit ad12049

Browse files
author
Joan Massich
committed
Remove nosetest with_setup
1 parent 846313b commit ad12049

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

sklearn/datasets/tests/test_base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from sklearn.utils.testing import assert_equal
2828
from sklearn.utils.testing import assert_raises
2929
from sklearn.utils.testing import assert_array_equal
30-
from sklearn.utils.testing import with_setup
3130

3231

3332
DATA_HOME = tempfile.mkdtemp(prefix="scikit_learn_data_home_test_")
@@ -85,33 +84,36 @@ def test_default_empty_load_files():
8584
assert_equal(res.DESCR, None)
8685

8786

88-
@with_setup(setup_load_files, teardown_load_files)
8987
def test_default_load_files():
88+
setup_load_files
9089
res = load_files(LOAD_FILES_ROOT)
9190
assert_equal(len(res.filenames), 1)
9291
assert_equal(len(res.target_names), 2)
9392
assert_equal(res.DESCR, None)
9493
assert_equal(res.data, [b("Hello World!\n")])
94+
teardown_load_files
9595

9696

97-
@with_setup(setup_load_files, teardown_load_files)
9897
def test_load_files_w_categories_desc_and_encoding():
98+
setup_load_files
9999
category = os.path.abspath(TEST_CATEGORY_DIR1).split('/').pop()
100100
res = load_files(LOAD_FILES_ROOT, description="test",
101101
categories=category, encoding="utf-8")
102102
assert_equal(len(res.filenames), 1)
103103
assert_equal(len(res.target_names), 1)
104104
assert_equal(res.DESCR, "test")
105105
assert_equal(res.data, [u("Hello World!\n")])
106+
teardown_load_files
106107

107108

108-
@with_setup(setup_load_files, teardown_load_files)
109109
def test_load_files_wo_load_content():
110+
setup_load_files
110111
res = load_files(LOAD_FILES_ROOT, load_content=False)
111112
assert_equal(len(res.filenames), 1)
112113
assert_equal(len(res.target_names), 2)
113114
assert_equal(res.DESCR, None)
114115
assert_equal(res.get('data'), None)
116+
teardown_load_files
115117

116118

117119
def test_load_sample_images():

sklearn/datasets/tests/test_mldata.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from sklearn.utils.testing import mock_mldata_urlopen
1414
from sklearn.utils.testing import assert_equal
1515
from sklearn.utils.testing import assert_raises
16-
from sklearn.utils.testing import with_setup
1716
from sklearn.utils.testing import assert_array_equal
1817

1918

@@ -43,10 +42,9 @@ def test_mldata_filename():
4342
assert_equal(mldata_filename(name), desired)
4443

4544

46-
@with_setup(setup_tmpdata, teardown_tmpdata)
4745
def test_download():
4846
"""Test that fetch_mldata is able to download and cache a data set."""
49-
47+
setup_tmpdata
5048
_urlopen_ref = datasets.mldata.urlopen
5149
datasets.mldata.urlopen = mock_mldata_urlopen({
5250
'mock': {
@@ -66,10 +64,11 @@ def test_download():
6664
fetch_mldata, 'not_existing_name')
6765
finally:
6866
datasets.mldata.urlopen = _urlopen_ref
67+
teardown_tmpdata
6968

7069

71-
@with_setup(setup_tmpdata, teardown_tmpdata)
7270
def test_fetch_one_column():
71+
setup_tmpdata
7372
_urlopen_ref = datasets.mldata.urlopen
7473
try:
7574
dataname = 'onecol'
@@ -90,10 +89,11 @@ def test_fetch_one_column():
9089
assert_equal(dset.data.shape, (3, 2))
9190
finally:
9291
datasets.mldata.urlopen = _urlopen_ref
92+
teardown_tmpdata
9393

9494

95-
@with_setup(setup_tmpdata, teardown_tmpdata)
9695
def test_fetch_multiple_column():
96+
setup_tmpdata
9797
_urlopen_ref = datasets.mldata.urlopen
9898
try:
9999
# create fake data set in cache
@@ -167,3 +167,4 @@ def test_fetch_multiple_column():
167167

168168
finally:
169169
datasets.mldata.urlopen = _urlopen_ref
170+
teardown_tmpdata

sklearn/utils/testing.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,18 @@
5656
raises = deprecated(deprecation_message)(_nose_raises)
5757
except ImportError:
5858
pass
59-
from nose import with_setup
59+
60+
try:
61+
from nose.tools import with_setup as _with_setup
62+
deprecation_message = (
63+
'sklearn.utils.testing.with_setup has been deprecated in version 0.20 '
64+
'and will be removed in 0.22.'
65+
'If your code relies on with_setup, please use'
66+
' nose.tools.with_setup instead.')
67+
with_setup = deprecated(deprecation_message)(_with_setup)
68+
except ImportError:
69+
pass
70+
6071

6172
from numpy.testing import assert_almost_equal
6273
from numpy.testing import assert_array_equal
@@ -754,10 +765,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
754765
_delete_folder(self.temp_folder)
755766

756767

757-
with_network = with_setup(check_skip_network)
758-
with_travis = with_setup(check_skip_travis)
759-
760-
761768
class _named_check(object):
762769
"""Wraps a check to show a useful description
763770

0 commit comments

Comments
 (0)