1313import sys
1414import warnings
1515from 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
3325from itertools import zip_longest
3426
@@ -51,14 +43,12 @@ def test_data(subdir=None, fname=None):
5143data_path = test_data ()
5244
5345
54- from .np_features import memmap_after_ufunc
55-
5646def 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
6454def 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
8777def 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-
214197EXTRA_SET = os .environ .get ('NIPY_EXTRA_TESTS' , '' ).split (',' )
215198
216199
217200def 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
223205def 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