3
3
# vi: set ft=python sts=4 ts=4 sw=4 et:
4
4
from __future__ import print_function , division , unicode_literals , absolute_import
5
5
from builtins import open
6
-
7
6
import os
8
- from tempfile import mkdtemp
9
- from shutil import rmtree
10
-
11
- import numpy as np
12
7
13
- import nibabel as nif
14
8
import pytest
15
- from nipype .interfaces .base import TraitError
9
+ from nipype .testing .fixtures import (create_files_in_directory_plus_dummy_file ,
10
+ create_surf_file_in_directory )
16
11
12
+ from nipype .interfaces .base import TraitError
17
13
import nipype .interfaces .freesurfer as fs
18
14
19
15
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' ]
26
- for f in filelist :
27
- hdr = nif .Nifti1Header ()
28
- shape = (3 , 3 , 3 , 4 )
29
- hdr .set_data_shape (shape )
30
- img = np .random .random (shape )
31
- nif .save (nif .Nifti1Image (img , np .eye (4 ), hdr ),
32
- os .path .join (outdir , f ))
33
- with open (os .path .join (outdir , 'reg.dat' ), 'wt' ) as fp :
34
- fp .write ('dummy file' )
35
- filelist .append ('reg.dat' )
36
-
37
- def clean_directory ():
38
- if os .path .exists (outdir ):
39
- rmtree (outdir )
40
- os .chdir (cwd )
41
-
42
- request .addfinalizer (clean_directory )
43
- return (filelist , outdir , cwd )
44
-
45
-
46
- @pytest .fixture ()
47
- def create_surf_file (request ):
48
- outdir = os .path .realpath (mkdtemp ())
49
- cwd = os .getcwd ()
50
- os .chdir (outdir )
51
- surf = 'lh.a.nii'
52
- hdr = nif .Nifti1Header ()
53
- shape = (1 , 100 , 1 )
54
- hdr .set_data_shape (shape )
55
- img = np .random .random (shape )
56
- nif .save (nif .Nifti1Image (img , np .eye (4 ), hdr ),
57
- os .path .join (outdir , surf ))
58
-
59
- def clean_directory ():
60
- if os .path .exists (outdir ):
61
- rmtree (outdir )
62
- os .chdir (cwd )
63
-
64
- request .addfinalizer (clean_directory )
65
- return (surf , outdir , cwd )
66
-
67
-
68
16
@pytest .mark .skipif (fs .no_freesurfer (), reason = "freesurfer is not installed" )
69
- def test_sample2surf (create_files_in_directory ):
17
+ def test_sample2surf (create_files_in_directory_plus_dummy_file ):
70
18
71
19
s2s = fs .SampleToSurface ()
72
20
# Test underlying command
@@ -76,7 +24,7 @@ def test_sample2surf(create_files_in_directory):
76
24
with pytest .raises (ValueError ): s2s .run ()
77
25
78
26
# Create testing files
79
- files , cwd , oldwd = create_files_in_directory
27
+ files , cwd = create_files_in_directory_plus_dummy_file
80
28
81
29
# Test input settings
82
30
s2s .inputs .source_file = files [0 ]
@@ -107,7 +55,7 @@ def set_illegal_range():
107
55
108
56
109
57
@pytest .mark .skipif (fs .no_freesurfer (), reason = "freesurfer is not installed" )
110
- def test_surfsmooth (create_surf_file ):
58
+ def test_surfsmooth (create_surf_file_in_directory ):
111
59
112
60
smooth = fs .SurfaceSmooth ()
113
61
@@ -118,7 +66,7 @@ def test_surfsmooth(create_surf_file):
118
66
with pytest .raises (ValueError ): smooth .run ()
119
67
120
68
# Create testing files
121
- surf , cwd , oldwd = create_surf_file
69
+ surf , cwd = create_surf_file_in_directory
122
70
123
71
# Test input settings
124
72
smooth .inputs .in_file = surf
@@ -139,7 +87,7 @@ def test_surfsmooth(create_surf_file):
139
87
140
88
141
89
@pytest .mark .skipif (fs .no_freesurfer (), reason = "freesurfer is not installed" )
142
- def test_surfxfm (create_surf_file ):
90
+ def test_surfxfm (create_surf_file_in_directory ):
143
91
144
92
xfm = fs .SurfaceTransform ()
145
93
@@ -150,7 +98,7 @@ def test_surfxfm(create_surf_file):
150
98
with pytest .raises (ValueError ): xfm .run ()
151
99
152
100
# Create testing files
153
- surf , cwd , oldwd = create_surf_file
101
+ surf , cwd = create_surf_file_in_directory
154
102
155
103
# Test input settings
156
104
xfm .inputs .source_file = surf
@@ -170,7 +118,7 @@ def test_surfxfm(create_surf_file):
170
118
171
119
172
120
@pytest .mark .skipif (fs .no_freesurfer (), reason = "freesurfer is not installed" )
173
- def test_surfshots (create_files_in_directory ):
121
+ def test_surfshots (create_files_in_directory_plus_dummy_file ):
174
122
175
123
fotos = fs .SurfaceSnapshots ()
176
124
@@ -181,7 +129,7 @@ def test_surfshots(create_files_in_directory):
181
129
with pytest .raises (ValueError ): fotos .run ()
182
130
183
131
# Create testing files
184
- files , cwd , oldwd = create_files_in_directory
132
+ files , cwd = create_files_in_directory_plus_dummy_file
185
133
186
134
# Test input settins
187
135
fotos .inputs .subject_id = "fsaverage"
0 commit comments