1111import nipype .interfaces .io as nio
1212from nipype .interfaces .base import Undefined
1313
14+
1415def test_datagrabber ():
1516 dg = nio .DataGrabber ()
1617 yield assert_equal , dg .inputs .template , Undefined
1718 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' : []}
1920
2021
2122def test_selectfiles ():
@@ -56,7 +57,7 @@ def test_datasink():
5657 yield assert_equal , ds .inputs .base_directory , Undefined
5758 yield assert_equal , ds .inputs .strip_dir , Undefined
5859 yield assert_equal , ds .inputs ._outputs , {}
59- ds = nio .DataSink (base_directory = 'foo' )
60+ ds = nio .DataSink (base_directory = 'foo' )
6061 yield assert_equal , ds .inputs .base_directory , 'foo'
6162 ds = nio .DataSink (infields = ['test' ])
6263 yield assert_true , 'test' in ds .inputs .copyable_trait_names ()
@@ -72,52 +73,58 @@ def test_datasink_substitutions():
7273 open (f , 'w' )
7374 ds = nio .DataSink (
7475 parametrization = False ,
75- base_directory = outdir ,
76- substitutions = [('ababab' , 'ABABAB' )],
76+ base_directory = outdir ,
77+ substitutions = [('ababab' , 'ABABAB' )],
7778 # end archoring ($) is used to assure operation on the filename
7879 # instead of possible temporary directories names matches
7980 # Patterns should be more comprehendable in the real-world usage
8081 # 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' )])
8485 setattr (ds .inputs , '@outdir' , files )
8586 ds .run ()
8687 yield assert_equal , \
8788 sorted ([os .path .basename (x ) for
8889 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
9091 shutil .rmtree (indir )
9192 shutil .rmtree (outdir )
9293
94+
9395def _temp_analyze_files ():
9496 """Generate temporary analyze file pair."""
95- fd , orig_img = mkstemp (suffix = '.img' , dir = mkdtemp ())
97+ fd , orig_img = mkstemp (suffix = '.img' , dir = mkdtemp ())
9698 orig_hdr = orig_img [:- 4 ] + '.hdr'
9799 fp = file (orig_hdr , 'w+' )
98100 fp .close ()
99101 return orig_img , orig_hdr
100102
103+
101104def test_datasink_copydir ():
102105 orig_img , orig_hdr = _temp_analyze_files ()
103106 outdir = mkdtemp ()
104107 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 )
107110 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 ))
109115 yield assert_true , file_exists ()
110116 shutil .rmtree (pth )
111117
112118 orig_img , orig_hdr = _temp_analyze_files ()
113119 pth , fname = os .path .split (orig_img )
114120 ds .inputs .remove_dest_dir = True
115- setattr (ds .inputs ,'outdir' ,pth )
121+ setattr (ds .inputs , 'outdir' , pth )
116122 ds .run ()
117123 yield assert_false , file_exists ()
118124 shutil .rmtree (outdir )
119125 shutil .rmtree (pth )
120126
127+
121128def test_freesurfersource ():
122129 fss = nio .FreeSurferSource ()
123130 yield assert_equal , fss .inputs .hemi , 'both'
0 commit comments