19
19
20
20
import pytest
21
21
22
- from .test_environment import (with_environment ,
23
- DATA_KEY ,
24
- USER_KEY )
22
+ from .test_environment import with_environment , DATA_KEY , USER_KEY
25
23
26
24
27
- @pytest .fixture ()
25
+ @pytest .fixture
28
26
def with_nimd_env (request , with_environment ):
29
27
DATA_FUNCS = {}
30
28
DATA_FUNCS ['home_dir_func' ] = nibd .get_nipy_user_dir
31
29
DATA_FUNCS ['sys_dir_func' ] = nibd .get_nipy_system_dir
32
30
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' ]
40
35
41
36
42
37
def test_datasource ():
@@ -162,8 +157,7 @@ def test_data_path(with_nimd_env):
162
157
with open (tmpfile , 'wt' ) as fobj :
163
158
fobj .write ('[DATA]\n ' )
164
159
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
167
161
168
162
169
163
def test_find_data_dir ():
@@ -206,10 +200,10 @@ def test_make_datasource(with_nimd_env):
206
200
assert ds .version == '0.1'
207
201
208
202
203
+ @pytest .mark .xfail (raises = DataError )
209
204
def 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
213
207
214
208
215
209
def test_bomber_inspect ():
@@ -218,13 +212,12 @@ def test_bomber_inspect():
218
212
219
213
220
214
def test_datasource_or_bomber (with_nimd_env ):
221
- pkg_def = dict (
222
- relpath = 'pkg' )
215
+ pkg_def = dict (relpath = 'pkg' )
223
216
with TemporaryDirectory () as tmpdir :
224
217
nibd .get_data_path = lambda : [tmpdir ]
225
218
ds = datasource_or_bomber (pkg_def )
226
219
with pytest .raises (DataError ):
227
- getattr ( ds , ' get_filename' )
220
+ ds . get_filename ( 'some_file.txt ' )
228
221
pkg_dir = pjoin (tmpdir , 'pkg' )
229
222
os .mkdir (pkg_dir )
230
223
tmpfile = pjoin (pkg_dir , 'config.ini' )
@@ -240,4 +233,4 @@ def test_datasource_or_bomber(with_nimd_env):
240
233
pkg_def ['min version' ] = '0.3'
241
234
ds = datasource_or_bomber (pkg_def ) # not OK
242
235
with pytest .raises (DataError ):
243
- getattr ( ds , ' get_filename' )
236
+ ds . get_filename ( 'some_file.txt ' )
0 commit comments