Skip to content

Commit e4cf7c2

Browse files
committed
RF - refactor data tests to not use configuration in users directory
1 parent 6839c61 commit e4cf7c2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

nibabel/tests/test_data.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
def setup_data_env():
3333
setup_environment()
3434
global DATA_FUNCS
35+
DATA_FUNCS['home_dir_func'] = nibd.get_nipy_user_dir
3536
DATA_FUNCS['sys_dir_func'] = nibd.get_nipy_system_dir
3637
DATA_FUNCS['path_func'] = nibd.get_data_path
3738

3839

3940
def teardown_data_env():
4041
teardown_environment()
42+
nibd.get_nipy_user_dir = DATA_FUNCS['home_dir_func']
4143
nibd.get_nipy_system_dir = DATA_FUNCS['sys_dir_func']
4244
nibd.get_data_path = DATA_FUNCS['path_func']
4345

@@ -135,7 +137,9 @@ def test_data_path():
135137
del env[DATA_KEY]
136138
if USER_KEY in env:
137139
del os.environ[USER_KEY]
140+
fake_user_dir = '/user/path'
138141
nibd.get_nipy_system_dir = lambda : ''
142+
nibd.get_nipy_user_dir = lambda : fake_user_dir
139143
# now we should only have anything pointed to in the user's dir
140144
old_pth = get_data_path()
141145
# We should have only sys.prefix and, iff sys.prefix == /usr,
@@ -144,8 +148,7 @@ def test_data_path():
144148
def_dirs = [pjoin(sys.prefix, 'share', 'nipy')]
145149
if sys.prefix == '/usr':
146150
def_dirs.append(pjoin('/usr/local', 'share', 'nipy'))
147-
home_nipy = pjoin(os.path.expanduser('~'), '.nipy')
148-
assert_equal(old_pth, def_dirs + [home_nipy])
151+
assert_equal(old_pth, def_dirs + ['/user/path'])
149152
# then we'll try adding some of our own
150153
tst_pth = '/a/path' + os.path.pathsep + '/b/ path'
151154
tst_list = ['/a/path', '/b/ path']
@@ -161,9 +164,9 @@ def test_data_path():
161164
with open(tmpfile, 'wt') as fobj:
162165
fobj.write('[DATA]\n')
163166
fobj.write('path = %s' % tst_pth)
164-
os.environ[USER_KEY] = tmpdir
167+
nibd.get_nipy_user_dir = lambda : tmpdir
165168
assert_equal(get_data_path(), tst_list + def_dirs + [tmpdir])
166-
del os.environ[USER_KEY]
169+
nibd.get_nipy_user_dir = lambda : fake_user_dir
167170
assert_equal(get_data_path(), old_pth)
168171
# with some trepidation, the system config files
169172
with TemporaryDirectory() as tmpdir:

0 commit comments

Comments
 (0)