1919
2020import pytest
2121
22- from .test_environment import (with_environment ,
23- DATA_KEY ,
24- USER_KEY )
22+ from .test_environment import with_environment , DATA_KEY , USER_KEY
2523
2624
27- @pytest .fixture ()
25+ @pytest .fixture
2826def with_nimd_env (request , with_environment ):
2927 DATA_FUNCS = {}
3028 DATA_FUNCS ['home_dir_func' ] = nibd .get_nipy_user_dir
3129 DATA_FUNCS ['sys_dir_func' ] = nibd .get_nipy_system_dir
3230 DATA_FUNCS ['path_func' ] = nibd .get_data_path
33-
34- def teardown_data_env ():
35- nibd .get_nipy_user_dir = DATA_FUNCS ['home_dir_func' ]
36- nibd .get_nipy_system_dir = DATA_FUNCS ['sys_dir_func' ]
37- nibd .get_data_path = DATA_FUNCS ['path_func' ]
38-
39- request .addfinalizer (teardown_data_env )
31+ yield
32+ nibd .get_nipy_user_dir = DATA_FUNCS ['home_dir_func' ]
33+ nibd .get_nipy_system_dir = DATA_FUNCS ['sys_dir_func' ]
34+ nibd .get_data_path = DATA_FUNCS ['path_func' ]
4035
4136
4237def test_datasource ():
@@ -162,8 +157,7 @@ def test_data_path(with_nimd_env):
162157 with open (tmpfile , 'wt' ) as fobj :
163158 fobj .write ('[DATA]\n ' )
164159 fobj .write ('path = %s\n ' % '/path/two' )
165- assert (get_data_path () ==
166- tst_list + ['/path/two' ] + old_pth )
160+ assert get_data_path () == tst_list + ['/path/two' ] + old_pth
167161
168162
169163def test_find_data_dir ():
@@ -206,10 +200,10 @@ def test_make_datasource(with_nimd_env):
206200 assert ds .version == '0.1'
207201
208202
203+ @pytest .mark .xfail (raises = DataError )
209204def test_bomber ():
210- with pytest .raises (DataError ):
211- b = Bomber ('bomber example' , 'a message' )
212- b .any_attribute # no error
205+ b = Bomber ('bomber example' , 'a message' )
206+ b .any_attribute # no error
213207
214208
215209def test_bomber_inspect ():
@@ -218,13 +212,12 @@ def test_bomber_inspect():
218212
219213
220214def test_datasource_or_bomber (with_nimd_env ):
221- pkg_def = dict (
222- relpath = 'pkg' )
215+ pkg_def = dict (relpath = 'pkg' )
223216 with TemporaryDirectory () as tmpdir :
224217 nibd .get_data_path = lambda : [tmpdir ]
225218 ds = datasource_or_bomber (pkg_def )
226219 with pytest .raises (DataError ):
227- getattr ( ds , ' get_filename' )
220+ ds . get_filename ( 'some_file.txt ' )
228221 pkg_dir = pjoin (tmpdir , 'pkg' )
229222 os .mkdir (pkg_dir )
230223 tmpfile = pjoin (pkg_dir , 'config.ini' )
@@ -240,4 +233,4 @@ def test_datasource_or_bomber(with_nimd_env):
240233 pkg_def ['min version' ] = '0.3'
241234 ds = datasource_or_bomber (pkg_def ) # not OK
242235 with pytest .raises (DataError ):
243- getattr ( ds , ' get_filename' )
236+ ds . get_filename ( 'some_file.txt ' )
0 commit comments