11
11
import nipype .interfaces .io as nio
12
12
from nipype .interfaces .base import Undefined
13
13
14
+
14
15
def test_datagrabber ():
15
16
dg = nio .DataGrabber ()
16
17
yield assert_equal , dg .inputs .template , Undefined
17
18
yield assert_equal , dg .inputs .base_directory , Undefined
18
- yield assert_equal , dg .inputs .template_args ,{'outfiles' : []}
19
+ yield assert_equal , dg .inputs .template_args , {'outfiles' : []}
19
20
20
21
21
22
def test_selectfiles ():
@@ -56,7 +57,7 @@ def test_datasink():
56
57
yield assert_equal , ds .inputs .base_directory , Undefined
57
58
yield assert_equal , ds .inputs .strip_dir , Undefined
58
59
yield assert_equal , ds .inputs ._outputs , {}
59
- ds = nio .DataSink (base_directory = 'foo' )
60
+ ds = nio .DataSink (base_directory = 'foo' )
60
61
yield assert_equal , ds .inputs .base_directory , 'foo'
61
62
ds = nio .DataSink (infields = ['test' ])
62
63
yield assert_true , 'test' in ds .inputs .copyable_trait_names ()
@@ -72,52 +73,58 @@ def test_datasink_substitutions():
72
73
open (f , 'w' )
73
74
ds = nio .DataSink (
74
75
parametrization = False ,
75
- base_directory = outdir ,
76
- substitutions = [('ababab' , 'ABABAB' )],
76
+ base_directory = outdir ,
77
+ substitutions = [('ababab' , 'ABABAB' )],
77
78
# end archoring ($) is used to assure operation on the filename
78
79
# instead of possible temporary directories names matches
79
80
# Patterns should be more comprehendable in the real-world usage
80
81
# cases since paths would be quite more sensible
81
- regexp_substitutions = [(r'xABABAB(\w*)\.n$' , r'a-\1-b.n' ),
82
- ('(.*%s)[-a]([^%s]*)$' % ((os .path .sep ,)* 2 ),
83
- r'\1!\2' )] )
82
+ regexp_substitutions = [(r'xABABAB(\w*)\.n$' , r'a-\1-b.n' ),
83
+ ('(.*%s)[-a]([^%s]*)$' % ((os .path .sep ,) * 2 ),
84
+ r'\1!\2' )])
84
85
setattr (ds .inputs , '@outdir' , files )
85
86
ds .run ()
86
87
yield assert_equal , \
87
88
sorted ([os .path .basename (x ) for
88
89
x in glob .glob (os .path .join (outdir , '*' ))]), \
89
- ['!-yz-b.n' , 'ABABAB.n' ] # so we got re used 2nd and both patterns
90
+ ['!-yz-b.n' , 'ABABAB.n' ] # so we got re used 2nd and both patterns
90
91
shutil .rmtree (indir )
91
92
shutil .rmtree (outdir )
92
93
94
+
93
95
def _temp_analyze_files ():
94
96
"""Generate temporary analyze file pair."""
95
- fd , orig_img = mkstemp (suffix = '.img' , dir = mkdtemp ())
97
+ fd , orig_img = mkstemp (suffix = '.img' , dir = mkdtemp ())
96
98
orig_hdr = orig_img [:- 4 ] + '.hdr'
97
99
fp = file (orig_hdr , 'w+' )
98
100
fp .close ()
99
101
return orig_img , orig_hdr
100
102
103
+
101
104
def test_datasink_copydir ():
102
105
orig_img , orig_hdr = _temp_analyze_files ()
103
106
outdir = mkdtemp ()
104
107
pth , fname = os .path .split (orig_img )
105
- ds = nio .DataSink (base_directory = outdir , parameterization = False )
106
- setattr (ds .inputs ,'@outdir' ,pth )
108
+ ds = nio .DataSink (base_directory = outdir , parameterization = False )
109
+ setattr (ds .inputs , '@outdir' , pth )
107
110
ds .run ()
108
- file_exists = lambda : os .path .exists (os .path .join (outdir , pth .split (os .path .sep )[- 1 ], fname ))
111
+ sep = os .path .sep
112
+ file_exists = lambda : os .path .exists (os .path .join (outdir ,
113
+ pth .split (sep )[- 1 ],
114
+ fname ))
109
115
yield assert_true , file_exists ()
110
116
shutil .rmtree (pth )
111
117
112
118
orig_img , orig_hdr = _temp_analyze_files ()
113
119
pth , fname = os .path .split (orig_img )
114
120
ds .inputs .remove_dest_dir = True
115
- setattr (ds .inputs ,'outdir' ,pth )
121
+ setattr (ds .inputs , 'outdir' , pth )
116
122
ds .run ()
117
123
yield assert_false , file_exists ()
118
124
shutil .rmtree (outdir )
119
125
shutil .rmtree (pth )
120
126
127
+
121
128
def test_freesurfersource ():
122
129
fss = nio .FreeSurferSource ()
123
130
yield assert_equal , fss .inputs .hemi , 'both'
0 commit comments