Skip to content

Commit 328c236

Browse files
authored
Merge pull request #883 from effigies/test/vanilla_unittest
TEST: Prefer vanilla unittest.skip* to pytest skips
2 parents afa0f2e + a223c07 commit 328c236

13 files changed

+54
-188
lines changed

.azure-pipelines/windows.yml

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -41,73 +41,17 @@ jobs:
4141
cd for_testing
4242
cp ../.coveragerc .
4343
nosetests --with-doctest --with-coverage --cover-package nibabel nibabel ^
44-
-I test_array_sequence ^
45-
-I test_tractogram ^
46-
-I test_api_validators ^
47-
-I test_arrayproxy ^
48-
-I test_arraywriters ^
49-
-I test_batteryrunners ^
50-
-I test_brikhead ^
51-
-I test_casting ^
52-
-I test_cifti2io_axes ^
53-
-I test_cifti2io_header ^
5444
-I test_data ^
55-
-I test_deprecated ^
56-
-I test_deprecator ^
57-
-I test_dicomwrappers ^
58-
-I test_dft ^
59-
-I test_ecat ^
60-
-I test_ecat_data ^
61-
-I test_endiancodes ^
6245
-I test_environment ^
6346
-I test_euler ^
64-
-I test_filebasedimages ^
65-
-I test_filehandles ^
66-
-I test_fileholders ^
67-
-I test_filename_parser ^
68-
-I test_files_interface ^
69-
-I test_fileslice ^
70-
-I test_fileutils ^
71-
-I test_floating ^
72-
-I test_funcs ^
7347
-I test_giftiio ^
74-
-I test_h5py_compat ^
75-
-I test_image_api ^
76-
-I test_image_load_save ^
77-
-I test_image_types ^
78-
-I test_imageclasses ^
79-
-I test_imageglobals ^
80-
-I test_io ^
81-
-I test_keywordonly ^
82-
-I test_loadsave ^
83-
-I test_minc1 ^
84-
-I test_minc2 ^
85-
-I test_minc2_data ^
86-
-I test_mriutils ^
8748
-I test_netcdf ^
88-
-I test_nibabel_data ^
89-
-I test_nifti1 ^
90-
-I test_nifti2 ^
91-
-I test_openers ^
92-
-I test_optpkg ^
93-
-I test_orientations ^
94-
-I test_parrec ^
95-
-I test_parrec_data ^
9649
-I test_pkg_info ^
97-
-I test_processing ^
98-
-I test_proxy_api ^
9950
-I test_quaternions ^
100-
-I test_recoder ^
101-
-I test_remmovalschedule ^
102-
-I test_round_trip ^
103-
-I test_rstutils ^
10451
-I test_scaling ^
105-
-I test_wrapstruct ^
106-
-I test_io ^
10752
-I test_scripts ^
10853
-I test_spaces ^
109-
-I test_testing ^
110-
-I test_wrapstruct
54+
-I test_testing
11155
displayName: 'Nose tests'
11256
condition: and(succeeded(), eq(variables['CHECK_TYPE'], 'nosetests'))
11357
- script: |

.travis.yml

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -134,73 +134,17 @@ script:
134134
cd for_testing
135135
cp ../.coveragerc .
136136
nosetests --with-doctest --with-coverage --cover-package nibabel nibabel \
137-
-I test_array_sequence \
138-
-I test_tractogram \
139-
-I test_api_validators \
140-
-I test_arrayproxy \
141-
-I test_arraywriters \
142-
-I test_batteryrunners \
143-
-I test_brikhead \
144-
-I test_casting \
145-
-I test_cifti2io_axes \
146-
-I test_cifti2io_header \
147137
-I test_data \
148-
-I test_deprecated \
149-
-I test_deprecator \
150-
-I test_dicomwrappers \
151-
-I test_dft \
152-
-I test_ecat \
153-
-I test_ecat_data \
154-
-I test_endiancodes \
155138
-I test_environment \
156139
-I test_euler \
157-
-I test_filebasedimages \
158-
-I test_filehandles \
159-
-I test_fileholders \
160-
-I test_filename_parser \
161-
-I test_files_interface \
162-
-I test_fileslice \
163-
-I test_fileutils \
164-
-I test_floating \
165-
-I test_funcs \
166140
-I test_giftiio \
167-
-I test_h5py_compat \
168-
-I test_image_api \
169-
-I test_image_load_save \
170-
-I test_image_types \
171-
-I test_imageclasses \
172-
-I test_imageglobals \
173-
-I test_io \
174-
-I test_keywordonly \
175-
-I test_loadsave \
176-
-I test_minc1 \
177-
-I test_minc2 \
178-
-I test_minc2_data \
179-
-I test_mriutils \
180141
-I test_netcdf \
181-
-I test_nibabel_data \
182-
-I test_nifti1 \
183-
-I test_nifti2 \
184-
-I test_openers \
185-
-I test_optpkg \
186-
-I test_orientations \
187-
-I test_parrec \
188-
-I test_parrec_data \
189142
-I test_pkg_info \
190-
-I test_processing \
191-
-I test_proxy_api \
192143
-I test_quaternions \
193-
-I test_recoder \
194-
-I test_remmovalschedule \
195-
-I test_round_trip \
196-
-I test_rstutils \
197144
-I test_scaling \
198-
-I test_wrapstruct \
199-
-I test_io \
200145
-I test_scripts \
201146
-I test_spaces \
202-
-I test_testing \
203-
-I test_wrapstruct
147+
-I test_testing
204148
elif [ "${CHECK_TYPE}" == "test" ]; then
205149
# Change into an innocuous directory and find tests from installation
206150
mkdir for_testing

nibabel/freesurfer/tests/test_io.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import hashlib
77
import warnings
88

9-
109
from ...tmpdirs import InTemporaryDirectory
1110

12-
11+
import unittest
1312
import pytest
1413
import numpy as np
1514
from numpy.testing import assert_allclose, assert_array_equal
@@ -36,8 +35,8 @@
3635
data_path = pjoin(nib_data, 'nitest-freesurfer', DATA_SDIR)
3736
have_freesurfer = isdir(data_path)
3837

39-
freesurfer_test = pytest.mark.skipif(not have_freesurfer,
40-
reason='cannot find freesurfer {0} directory'.format(DATA_SDIR))
38+
freesurfer_test = unittest.skipUnless(have_freesurfer,
39+
'cannot find freesurfer {0} directory'.format(DATA_SDIR))
4140

4241
def _hash_file_content(fname):
4342
hasher = hashlib.md5()

nibabel/testing_pytest/__init__.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313
import sys
1414
import warnings
1515
from pkg_resources import resource_filename
16-
from os.path import dirname, abspath, join as pjoin
1716

1817
import unittest
1918

2019
import numpy as np
21-
from numpy.testing import assert_array_equal, assert_warns
22-
from numpy.testing import dec
23-
skipif = dec.skipif
24-
slow = dec.slow
20+
from numpy.testing import assert_array_equal
2521

26-
from ..deprecated import deprecate_with_version as _deprecate_with_version
2722
from .np_features import memmap_after_ufunc
2823
from .helpers import bytesio_filemap, bytesio_round_trip, assert_data_similar
2924

@@ -63,7 +58,7 @@ def assert_allclose_safely(a, b, match_nans=True, rtol=1e-5, atol=1e-8):
6358
a, b = np.broadcast_arrays(a, b)
6459
if match_nans:
6560
nans = np.isnan(a)
66-
np.testing.assert_array_equal(nans, np.isnan(b))
61+
assert_array_equal(nans, np.isnan(b))
6762
to_test = ~nans
6863
else:
6964
to_test = np.ones(a.shape, dtype=bool)
@@ -199,20 +194,12 @@ class suppress_warnings(error_warnings):
199194
filter = 'ignore'
200195

201196

202-
@_deprecate_with_version('catch_warn_reset is deprecated; use '
203-
'nibabel.testing.clear_and_catch_warnings.',
204-
since='2.1.0', until='3.0.0')
205-
class catch_warn_reset(clear_and_catch_warnings):
206-
pass
207-
208-
209197
EXTRA_SET = os.environ.get('NIPY_EXTRA_TESTS', '').split(',')
210198

211199

212200
def runif_extra_has(test_str):
213201
"""Decorator checks to see if NIPY_EXTRA_TESTS env var contains test_str"""
214-
return skipif(test_str not in EXTRA_SET,
215-
"Skip {0} tests.".format(test_str))
202+
return unittest.skipUnless(test_str in EXTRA_SET, "Skip {0} tests.".format(test_str))
216203

217204

218205
def assert_arr_dict_equal(dict1, dict2):

nibabel/tests/nibabel_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from os import environ, listdir
55
from os.path import dirname, realpath, join as pjoin, isdir, exists
66

7-
import pytest
7+
import unittest
88

99

1010
def get_nibabel_data():
@@ -39,11 +39,11 @@ def needs_nibabel_data(subdir=None):
3939
"""
4040
nibabel_data = get_nibabel_data()
4141
if nibabel_data == '':
42-
return pytest.mark.skipif(True, reason="Need nibabel-data directory for this test")
42+
return unittest.skip("Need nibabel-data directory for this test")
4343
if subdir is None:
44-
return pytest.mark.skipif(False, reason="Don't skip")
44+
return lambda x: x
4545
required_path = pjoin(nibabel_data, subdir)
4646
# Path should not be empty (as is the case for not-updated submodules)
4747
have_files = exists(required_path) and len(listdir(required_path)) > 0
48-
return pytest.mark.skipif(not have_files,
49-
reason="Need files in {0} for these tests".format(required_path))
48+
return unittest.skipUnless(have_files,
49+
"Need files in {0} for these tests".format(required_path))

nibabel/tests/test_dft.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .. import dft
1111
from .. import nifti1
1212

13+
import unittest
1314
import pytest
1415

1516
# Shield optional package imports
@@ -22,10 +23,12 @@
2223
data_dir = pjoin(dirname(__file__), 'data')
2324

2425

25-
pytestmark = [
26-
pytest.mark.skipif(os.name == 'nt', reason='FUSE not available for windows, skipping dft tests'),
27-
pytest.mark.skipif(not have_dicom, reason='Need pydicom for dft tests, skipping')
28-
]
26+
def setUpModule():
27+
if os.name == 'nt':
28+
raise unittest.SkipTest('FUSE not available for windows, skipping dft tests')
29+
if not have_dicom:
30+
raise unittest.SkipTest('Need pydicom for dft tests, skipping')
31+
2932

3033
def test_init():
3134
dft.clear_cache()
@@ -76,7 +79,7 @@ def test_storage_instance():
7679
pass
7780

7881

79-
@pytest.mark.skipif(not have_pil, reason='could not import PIL.Image')
82+
@unittest.skipUnless(have_pil, 'could not import PIL.Image')
8083
def test_png():
8184
studies = dft.get_studies(data_dir)
8285
data = studies[0].series[0].as_png()

nibabel/tests/test_image_api.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from ..spatialimages import SpatialImage
4242
from .. import minc1, minc2, parrec, brikhead
4343

44+
import unittest
4445
import pytest
4546

4647
from numpy.testing import assert_almost_equal, assert_array_equal, assert_warns, assert_allclose
@@ -121,7 +122,7 @@ def validate_filenames(self, imaker, params):
121122
# Validate the filename, file_map interface
122123

123124
if not self.can_save:
124-
pytest.skip()
125+
raise unittest.SkipTest
125126
img = imaker()
126127
img.set_data_dtype(np.float32) # to avoid rounding in load / save
127128
# Make sure the object does not have a file_map
@@ -706,8 +707,12 @@ class TestMinc1API(ImageHeaderAPI):
706707
example_images = MINC1_EXAMPLE_IMAGES
707708

708709

709-
@pytest.mark.skipif(not have_h5py, reason="Need h5py for Minc2 tests")
710710
class TestMinc2API(TestMinc1API):
711+
712+
def __init__(self):
713+
if not have_h5py:
714+
raise unittest.SkipTest('Need h5py for these tests')
715+
711716
klass = image_maker = Minc2Image
712717
loader = minc2.load
713718
example_images = MINC2_EXAMPLE_IMAGES

nibabel/tests/test_parrec_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from .nibabel_data import get_nibabel_data, needs_nibabel_data
1414

15+
import unittest
1516
import pytest
1617
from numpy.testing import assert_almost_equal
1718

@@ -60,7 +61,7 @@ def test_fieldmap():
6061
fieldmap_nii = pjoin(BALLS, 'NIFTI', 'fieldmap.nii.gz')
6162
load(fieldmap_par)
6263
top_load(fieldmap_nii)
63-
raise pytest.skip('Fieldmap remains puzzling')
64+
raise unittest.SkipTest('Fieldmap remains puzzling')
6465

6566

6667
@needs_nibabel_data('parrec_oblique')

nibabel/tests/test_processing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
voxel_sizes)
2828
from nibabel.eulerangles import euler2mat
2929

30-
from numpy.testing import (assert_almost_equal,
31-
assert_array_equal)
30+
from numpy.testing import assert_almost_equal, assert_array_equal
31+
import unittest
3232
import pytest
3333

3434
from nibabel.tests.test_spaces import assert_all_in, get_outspace_params
3535
from nibabel.testing import assert_allclose_safely
3636

37-
needs_scipy = pytest.mark.skipif(not have_scipy, reason='These tests need scipy')
37+
needs_scipy = unittest.skipUnless(have_scipy, 'These tests need scipy')
3838

3939
DATA_DIR = pjoin(dirname(__file__), 'data')
4040

nibabel/tests/test_proxy_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
from ..arrayproxy import ArrayProxy, is_proxy
5353

54+
import unittest
5455
import pytest
5556
from numpy.testing import assert_almost_equal, assert_array_equal, assert_allclose
5657

@@ -428,7 +429,7 @@ def eg_func():
428429
arr_out=arr_out))
429430

430431
def validate_header_isolated(self, pmaker, params):
431-
raise pytest.skip('ECAT header does not support dtype get')
432+
raise unittest.SkipTest('ECAT header does not support dtype get')
432433

433434

434435
class TestPARRECAPI(_TestProxyAPI):

nibabel/tests/test_scripts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ..loadsave import load
2121
from ..orientations import flip_axis, aff2axcodes, inv_ornt_aff
2222

23+
import unittest
2324
import pytest
2425
from numpy.testing import assert_almost_equal
2526

@@ -120,7 +121,7 @@ def test_nib_ls(args):
120121
check_nib_ls_example4d(*args)
121122

122123

123-
@pytest.mark.skipif(not load_small_file(), reason="can't load the small.mnc file")
124+
@unittest.skipUnless(load_small_file(), "Can't load the small.mnc file")
124125
@script_test
125126
def test_nib_ls_multiple():
126127
# verify that correctly lists/formats for multiple files

0 commit comments

Comments
 (0)