Skip to content

Commit 8db1cd9

Browse files
committed
changing testing_pytest back to testing
1 parent d5ef496 commit 8db1cd9

38 files changed

+63
-314
lines changed

nibabel/cifti2/tests/test_new_cifti2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from nibabel.tmpdirs import InTemporaryDirectory
1414

1515
import pytest
16-
from ...testing_pytest import (
16+
from ...testing import (
1717
clear_and_catch_warnings, error_warnings, suppress_warnings, assert_array_equal)
1818

1919
affine = [[-1.5, 0, 0, 90],

nibabel/freesurfer/tests/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from ...tests.nibabel_data import get_nibabel_data, needs_nibabel_data
2121
from ...fileslice import strided_scalar
22-
from ...testing_pytest import clear_and_catch_warnings
22+
from ...testing import clear_and_catch_warnings
2323

2424
DATA_SDIR = 'fsaverage'
2525

nibabel/freesurfer/tests/test_mghformat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_almost_equal
3030

31-
from ...testing_pytest import data_path
31+
from ...testing import data_path
3232

3333
from ...tests import test_spatialimages as tsi
3434
from ...tests.test_wrapstruct import _TestLabeledWrapStruct

nibabel/gifti/tests/test_gifti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from numpy.testing import assert_array_almost_equal, assert_array_equal
1818
import pytest
19-
from ...testing_pytest import clear_and_catch_warnings, test_data
19+
from ...testing import clear_and_catch_warnings, test_data
2020
from .test_parse_gifti_fast import (DATA_FILE1, DATA_FILE2, DATA_FILE3,
2121
DATA_FILE4, DATA_FILE5, DATA_FILE6)
2222
import itertools

nibabel/gifti/tests/test_parse_gifti_fast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from numpy.testing import assert_array_almost_equal
2424

2525
import pytest
26-
from ...testing_pytest import clear_and_catch_warnings
26+
from ...testing import clear_and_catch_warnings
2727

2828

2929
IO_DATA_PATH = pjoin(dirname(__file__), 'data')

nibabel/streamlines/tests/test_array_sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77

88
import pytest
9-
from ...testing_pytest import assert_arrays_equal
9+
from ...testing import assert_arrays_equal
1010
from numpy.testing import assert_array_equal
1111

1212
from ..array_sequence import ArraySequence, is_array_sequence, concatenate

nibabel/streamlines/tests/test_tck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import pytest
1818
from numpy.testing import assert_array_equal
19-
from ...testing_pytest import data_path, clear_and_catch_warnings
19+
from ...testing import data_path, clear_and_catch_warnings
2020
from .test_tractogram import assert_tractogram_equal
2121

2222
DATA = {}

nibabel/streamlines/tests/test_tractogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections import defaultdict
88

99
import pytest
10-
from ...testing_pytest import assert_arrays_equal, clear_and_catch_warnings
10+
from ...testing import assert_arrays_equal, clear_and_catch_warnings
1111
from numpy.testing import assert_array_equal, assert_array_almost_equal
1212

1313
from .. import tractogram as module_tractogram

nibabel/streamlines/tests/test_trk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from io import BytesIO
99

1010
import pytest
11-
from ...testing_pytest import data_path, clear_and_catch_warnings, assert_arr_dict_equal
11+
from ...testing import data_path, clear_and_catch_warnings, assert_arr_dict_equal
1212
from numpy.testing import assert_array_equal
1313

1414
from .test_tractogram import assert_tractogram_equal

nibabel/testing/__init__.py

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

18-
import numpy as np
19-
from numpy.testing import assert_array_equal, assert_warns
20-
from numpy.testing import dec
21-
skipif = dec.skipif
22-
slow = dec.slow
17+
import unittest
2318

24-
from ..deprecated import deprecate_with_version as _deprecate_with_version
19+
import numpy as np
20+
from numpy.testing import assert_array_equal
2521

26-
# Allow failed import of nose if not now running tests
27-
try:
28-
from nose.tools import (assert_equal, assert_not_equal,
29-
assert_true, assert_false, assert_raises)
30-
except ImportError:
31-
pass
22+
from .np_features import memmap_after_ufunc
23+
from .helpers import bytesio_filemap, bytesio_round_trip, assert_data_similar
3224

3325
from itertools import zip_longest
3426

@@ -51,14 +43,12 @@ def test_data(subdir=None, fname=None):
5143
data_path = test_data()
5244

5345

54-
from .np_features import memmap_after_ufunc
55-
5646
def assert_dt_equal(a, b):
5747
""" Assert two numpy dtype specifiers are equal
5848
5949
Avoids failed comparison between int32 / int64 and intp
6050
"""
61-
assert_equal(np.dtype(a).str, np.dtype(b).str)
51+
assert np.dtype(a).str == np.dtype(b).str
6252

6353

6454
def assert_allclose_safely(a, b, match_nans=True, rtol=1e-5, atol=1e-8):
@@ -68,7 +58,7 @@ def assert_allclose_safely(a, b, match_nans=True, rtol=1e-5, atol=1e-8):
6858
a, b = np.broadcast_arrays(a, b)
6959
if match_nans:
7060
nans = np.isnan(a)
71-
np.testing.assert_array_equal(nans, np.isnan(b))
61+
assert_array_equal(nans, np.isnan(b))
7262
to_test = ~nans
7363
else:
7464
to_test = np.ones(a.shape, dtype=bool)
@@ -81,13 +71,13 @@ def assert_allclose_safely(a, b, match_nans=True, rtol=1e-5, atol=1e-8):
8171
a = a.astype(float)
8272
if b.dtype.kind in 'ui':
8373
b = b.astype(float)
84-
assert_true(np.allclose(a, b, rtol=rtol, atol=atol))
74+
assert np.allclose(a, b, rtol=rtol, atol=atol)
8575

8676

8777
def assert_arrays_equal(arrays1, arrays2):
8878
""" Check two iterables yield the same sequence of arrays. """
8979
for arr1, arr2 in zip_longest(arrays1, arrays2, fillvalue=None):
90-
assert_false(arr1 is None or arr2 is None)
80+
assert (arr1 is not None and arr2 is not None)
9181
assert_array_equal(arr1, arr2)
9282

9383

@@ -204,26 +194,30 @@ class suppress_warnings(error_warnings):
204194
filter = 'ignore'
205195

206196

207-
@_deprecate_with_version('catch_warn_reset is deprecated; use '
208-
'nibabel.testing.clear_and_catch_warnings.',
209-
since='2.1.0', until='3.0.0')
210-
class catch_warn_reset(clear_and_catch_warnings):
211-
pass
212-
213-
214197
EXTRA_SET = os.environ.get('NIPY_EXTRA_TESTS', '').split(',')
215198

216199

217200
def runif_extra_has(test_str):
218201
"""Decorator checks to see if NIPY_EXTRA_TESTS env var contains test_str"""
219-
return skipif(test_str not in EXTRA_SET,
220-
"Skip {0} tests.".format(test_str))
202+
return unittest.skipUnless(test_str in EXTRA_SET, "Skip {0} tests.".format(test_str))
221203

222204

223205
def assert_arr_dict_equal(dict1, dict2):
224206
""" Assert that two dicts are equal, where dicts contain arrays
225207
"""
226-
assert_equal(set(dict1), set(dict2))
208+
assert set(dict1) == set(dict2)
227209
for key, value1 in dict1.items():
228210
value2 = dict2[key]
229211
assert_array_equal(value1, value2)
212+
213+
214+
class BaseTestCase(unittest.TestCase):
215+
""" TestCase that does not attempt to run if prefixed with a ``_``
216+
217+
This restores the nose-like behavior of skipping so-named test cases
218+
in test runners like pytest.
219+
"""
220+
def setUp(self):
221+
if self.__class__.__name__.startswith('_'):
222+
raise unittest.SkipTest("Base test case - subclass to run")
223+
super().setUp()

0 commit comments

Comments
 (0)