Skip to content

Commit 0530484

Browse files
committed
ENH: Add general test data retriever
1 parent 154321c commit 0530484

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

nibabel/testing/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import sys
1515
import warnings
16+
from pkg_resources import resource_filename
1617
from os.path import dirname, abspath, join as pjoin
1718

1819
import numpy as np
@@ -32,8 +33,23 @@
3233

3334
from six.moves import zip_longest
3435

36+
37+
def test_data(subdir=None, fname=None):
38+
if subdir is None:
39+
resource = 'tests/data'
40+
elif subdir in ('gifti', 'nicom', 'externals'):
41+
resource = '%s/tests/data' % subdir
42+
else:
43+
raise ValueError("Unknown test data directory: %s" % subdir)
44+
45+
if fname is not None:
46+
resource = os.path.join(resource, fname)
47+
48+
return resource_filename('nibabel', resource)
49+
50+
3551
# set path to example data
36-
data_path = abspath(pjoin(dirname(__file__), '..', 'tests', 'data'))
52+
data_path = test_data()
3753

3854

3955
from .np_features import memmap_after_ufunc

0 commit comments

Comments
 (0)