1414import sys
1515import warnings
1616from os .path import dirname , abspath , join as pjoin
17- from nibabel .externals .six .moves import zip_longest
1817
1918import numpy as np
2019from numpy .testing import assert_array_equal
2726except ImportError :
2827 pass
2928
29+ from nibabel .externals .six .moves import zip_longest
30+
3031# set path to example data
3132data_path = abspath (pjoin (dirname (__file__ ), '..' , 'tests' , 'data' ))
3233
@@ -64,6 +65,22 @@ def assert_allclose_safely(a, b, match_nans=True, rtol=1e-5, atol=1e-8):
6465 assert_true (np .allclose (a , b , rtol = rtol , atol = atol ))
6566
6667
68+ def check_iteration (iterable ):
69+ """ Checks that an object can be iterated through without errors. """
70+ try :
71+ for _ in iterable :
72+ pass
73+ except :
74+ return False
75+
76+ return True
77+
78+
79+ def assert_arrays_equal (arrays1 , arrays2 ):
80+ for arr1 , arr2 in zip_longest (arrays1 , arrays2 , fillvalue = None ):
81+ assert_array_equal (arr1 , arr2 )
82+
83+
6784def assert_re_in (regex , c , flags = 0 ):
6885 """Assert that container (list, str, etc) contains entry matching the regex
6986 """
@@ -75,7 +92,6 @@ def assert_re_in(regex, c, flags=0):
7592 raise AssertionError ("Not a single entry matched %r in %r" % (regex , c ))
7693
7794
78-
7995def get_fresh_mod (mod_name = __name__ ):
8096 # Get this module, with warning registry empty
8197 my_mod = sys .modules [mod_name ]
@@ -179,7 +195,17 @@ class suppress_warnings(error_warnings):
179195
180196
181197class catch_warn_reset (clear_and_catch_warnings ):
198+
182199 def __init__ (self , * args , ** kwargs ):
183200 warnings .warn ('catch_warn_reset is deprecated and will be removed in '
184201 'nibabel v3.0; use nibabel.testing.clear_and_catch_warnings.' ,
185202 FutureWarning )
203+
204+
205+ EXTRA_SET = os .environ .get ('NIPY_EXTRA_TESTS' , '' ).split (',' )
206+
207+
208+ def runif_extra_has (test_str ):
209+ """Decorator checks to see if NIPY_EXTRA_TESTS env var contains test_str"""
210+ return skipif (test_str not in EXTRA_SET ,
211+ "Skip {0} tests." .format (test_str ))
0 commit comments