1717from nipype .interfaces .fsl .base import FSLCommand
1818
1919
20- @pytest .fixture ()
21- def create_files_in_directory (request ):
22- outdir = os .path .realpath (mkdtemp ())
23- cwd = os .getcwd ()
24- os .chdir (outdir )
25- filelist = ['a.nii' , 'b.nii' ]
20+ def nifti_image_files (outdir , filelist , shape ):
2621 for f in filelist :
2722 hdr = nb .Nifti1Header ()
28- shape = (3 , 3 , 3 , 4 )
2923 hdr .set_data_shape (shape )
3024 img = np .random .random (shape )
3125 nb .save (nb .Nifti1Image (img , np .eye (4 ), hdr ),
3226 os .path .join (outdir , f ))
3327
28+
29+ @pytest .fixture ()
30+ def create_files_in_directory (request ):
31+ outdir = os .path .realpath (mkdtemp ())
32+ cwd = os .getcwd ()
33+ os .chdir (outdir )
34+ filelist = ['a.nii' , 'b.nii' ]
35+ nifti_image_files (outdir , filelist , shape = (3 ,3 ,3 ,4 ))
36+
3437 def clean_directory ():
3538 if os .path .exists (outdir ):
3639 rmtree (outdir )
@@ -46,13 +49,7 @@ def create_files_in_directory_plus_dummy_file(request):
4649 cwd = os .getcwd ()
4750 os .chdir (outdir )
4851 filelist = ['a.nii' , 'b.nii' ]
49- for f in filelist :
50- hdr = nb .Nifti1Header ()
51- shape = (3 , 3 , 3 , 4 )
52- hdr .set_data_shape (shape )
53- img = np .random .random (shape )
54- nb .save (nb .Nifti1Image (img , np .eye (4 ), hdr ),
55- os .path .join (outdir , f ))
52+ nifti_image_files (outdir , filelist , shape = (3 ,3 ,3 ,4 ))
5653
5754 with open (os .path .join (outdir , 'reg.dat' ), 'wt' ) as fp :
5855 fp .write ('dummy file' )
@@ -73,12 +70,7 @@ def create_surf_file_in_directory(request):
7370 cwd = os .getcwd ()
7471 os .chdir (outdir )
7572 surf = 'lh.a.nii'
76- hdr = nif .Nifti1Header ()
77- shape = (1 , 100 , 1 )
78- hdr .set_data_shape (shape )
79- img = np .random .random (shape )
80- nif .save (nif .Nifti1Image (img , np .eye (4 ), hdr ),
81- os .path .join (outdir , surf ))
73+ nifti_image_files (outdir , filelist = surf , shape = (1 ,100 ,1 ))
8274
8375 def clean_directory ():
8476 if os .path .exists (outdir ):
@@ -107,15 +99,8 @@ def create_files_in_directory_plus_output_type(request):
10799 testdir = os .path .realpath (mkdtemp ())
108100 origdir = os .getcwd ()
109101 os .chdir (testdir )
110-
111102 filelist = ['a.nii' , 'b.nii' ]
112- for f in filelist :
113- hdr = nb .Nifti1Header ()
114- shape = (3 , 3 , 3 , 4 )
115- hdr .set_data_shape (shape )
116- img = np .random .random (shape )
117- nb .save (nb .Nifti1Image (img , np .eye (4 ), hdr ),
118- os .path .join (testdir , f ))
103+ nifti_image_files (testdir , filelist , shape = (3 ,3 ,3 ,4 ))
119104
120105 out_ext = Info .output_type_to_ext (Info .output_type ())
121106
0 commit comments