Skip to content

Commit 343f74a

Browse files
committed
RF+BF: '' from get_nibabel_data() when missing
Return empty string from ``get_nibabel_data()`` if directory does not exist, instead of None. Doing this means we can use os.path.join on the output even if it the directory doesn't exist. The resulting filenames don't make sense, but the decorator checks for this in any case, so the filenames don't get used.
1 parent d3b357c commit 343f74a

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

nibabel/tests/nibabel_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def get_nibabel_data():
11-
""" Return path to nibabel-data or None if missing
11+
""" Return path to nibabel-data or empty string if missing
1212
1313
First use ``NIBABEL_DATA_DIR`` environment variable.
1414
@@ -20,7 +20,7 @@ def get_nibabel_data():
2020
mod = __import__('nibabel')
2121
containing_path = dirname(dirname(realpath(mod.__file__)))
2222
nibabel_data = pjoin(containing_path, 'nibabel-data')
23-
return nibabel_data if isdir(nibabel_data) else None
23+
return nibabel_data if isdir(nibabel_data) else ''
2424

2525

2626
def needs_nibabel_data(subdir = None):
@@ -38,7 +38,7 @@ def needs_nibabel_data(subdir = None):
3838
Decorator skipping tests if required directory not present
3939
"""
4040
nibabel_data = get_nibabel_data()
41-
if nibabel_data is None:
41+
if nibabel_data == '':
4242
return skipif(True, "Need nibabel-data directory for this test")
4343
if subdir is None:
4444
return skipif(False)

nibabel/tests/test_minc2_data.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
from nose.tools import assert_equal
2626
from numpy.testing import (assert_array_equal, assert_almost_equal)
2727

28-
NIBABEL_DATA = get_nibabel_data()
29-
if NIBABEL_DATA is not None:
30-
MINC2_PATH = pjoin(NIBABEL_DATA, 'nitest-minc2')
28+
MINC2_PATH = pjoin(get_nibabel_data(), 'nitest-minc2')
3129

3230

3331
def _make_affine(coses, zooms, starts):

nibabel/tests/test_nibabel_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def test_get_nibabel_data():
2525
if isdir(local_data):
2626
assert_equal(nibd.get_nibabel_data(), local_data)
2727
else:
28-
assert_equal(nibd.get_nibabel_data(), None)
28+
assert_equal(nibd.get_nibabel_data(), '')
2929
nibd.environ['NIBABEL_DATA_DIR'] = 'not_a_path'
30-
assert_equal(nibd.get_nibabel_data(), None)
30+
assert_equal(nibd.get_nibabel_data(), '')
3131
nibd.environ['NIBABEL_DATA_DIR'] = MY_DIR
3232
assert_equal(nibd.get_nibabel_data(), MY_DIR)

nibabel/tests/test_parrec_data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
from numpy.testing import assert_almost_equal
1919

20-
NIBABEL_DATA = get_nibabel_data()
21-
BALLS = None if NIBABEL_DATA is None else pjoin(NIBABEL_DATA, 'nitest-balls1')
20+
BALLS = pjoin(get_nibabel_data(), 'nitest-balls1')
2221

2322
# Amount by which affine translation differs from NIFTI conversion
2423
AFF_OFF = [-0.93644031, -0.95572686, 0.03288748]

0 commit comments

Comments
 (0)