Skip to content

Commit 38ebe17

Browse files
author
Ben Cipollini
committed
TST: Add a runif_extra_has decorator.
1 parent 2e65cf9 commit 38ebe17

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

nibabel/testing/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
''' Utilities for testing '''
1010
from __future__ import division, print_function
1111

12+
import os
1213
import sys
1314
import warnings
1415
from os.path import dirname, abspath, join as pjoin
1516

1617
import numpy as np
1718

19+
from numpy.testing.decorators import skipif
1820
# Allow failed import of nose if not now running tests
1921
try:
2022
from nose.tools import (assert_equal, assert_not_equal,
@@ -164,3 +166,11 @@ def __init__(self, *args, **kwargs):
164166
warnings.warn('catch_warn_reset is deprecated and will be removed in '
165167
'nibabel v3.0; use nibabel.testing.clear_and_catch_warnings.',
166168
FutureWarning)
169+
170+
171+
def runif_extra_has(test_str):
172+
"""Decorator checks to see if NIPY_EXTRA_TESTS env var contains test_str"""
173+
def decorator(func):
174+
skip_set = os.environ.get('NIPY_EXTRA_TESTS', '').split(',')
175+
return skipif(test_str not in skip_set, "Skip slow tests.")(func)
176+
return decorator

nibabel/tests/test_nifti1.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313

1414
import numpy as np
1515

16-
from ..externals.six import BytesIO
17-
from ..casting import type_info, have_binary128
18-
from ..tmpdirs import InTemporaryDirectory
19-
from ..spatialimages import HeaderDataError
20-
from ..eulerangles import euler2mat
21-
from ..affines import from_matvec
22-
from .. import nifti1 as nifti1
23-
from ..nifti1 import (load, Nifti1Header, Nifti1PairHeader, Nifti1Image,
24-
Nifti1Pair, Nifti1Extension, Nifti1Extensions,
25-
data_type_codes, extension_codes, slice_order_codes)
26-
16+
from nibabel import nifti1 as nifti1
17+
from nibabel.affines import from_matvec
18+
from nibabel.casting import type_info, have_binary128
19+
from nibabel.eulerangles import euler2mat
20+
from nibabel.externals.six import BytesIO
21+
from nibabel.nifti1 import (load, Nifti1Header, Nifti1PairHeader, Nifti1Image,
22+
Nifti1Pair, Nifti1Extension, Nifti1Extensions,
23+
data_type_codes, extension_codes,
24+
slice_order_codes)
25+
from nibabel.openers import ImageOpener
26+
from nibabel.spatialimages import HeaderDataError
27+
from nibabel.tmpdirs import InTemporaryDirectory
2728
from ..freesurfer import load as mghload
2829

2930
from .test_arraywriters import rt_err_estimate, IUINT_TYPES
@@ -35,7 +36,7 @@
3536
from nose.tools import (assert_true, assert_false, assert_equal,
3637
assert_raises)
3738

38-
from ..testing import data_path, suppress_warnings
39+
from ..testing import data_path, suppress_warnings, runif_extra_has
3940

4041
from . import test_analyze as tana
4142
from . import test_spm99analyze as tspm
@@ -1244,6 +1245,7 @@ def test_rt_bias(self):
12441245
assert_true(np.abs(bias) < bias_thresh)
12451246

12461247

1248+
@runif_extra_has('slow')
12471249
def test_large_nifti1():
12481250
image_shape = (91, 109, 91, 1200)
12491251
img = Nifti1Image(np.zeros(image_shape, dtype=np.float32),
@@ -1252,5 +1254,5 @@ def test_large_nifti1():
12521254
img.to_filename('test.nii.gz')
12531255
del img
12541256
data = load('test.nii.gz').get_data()
1255-
assert_equal(np.asarray(image_shape), data.shape)
1257+
assert_array_equal(np.asarray(image_shape), data.shape)
12561258
assert_true(np.all(data == 0.))

0 commit comments

Comments
 (0)