@@ -194,18 +194,16 @@ def test_specs(self, uri):
194
194
195
195
if not issubclass (classinst , BaseInterface ):
196
196
continue
197
- #print uri, c, uri_short
198
197
testdir = os .path .join (* (uri .split ('.' )[:- 1 ] + ['tests' ]))
199
198
if not os .path .exists (testdir ):
200
199
os .makedirs (testdir )
201
- #print testdir
202
200
testfile = os .path .join (testdir , 'test_auto_%s.py' % c )
203
201
204
202
with open (testfile , 'wt' ) as fp :
205
203
cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT' ,
206
204
'from nipype.testing import assert_equal' ,
207
205
'from %s import %s' % (uri , c ),
208
- 'def test_%s ():' % c ]
206
+ 'def test_%s_inputs ():' % c ]
209
207
input_fields = ''
210
208
for traitname , trait in classinst .input_spec ().traits (transient = None ).items ():
211
209
input_fields += '%s=dict(' % traitname
@@ -227,7 +225,7 @@ def test_specs(self, uri):
227
225
for key, metadata in input_map.items():
228
226
for metakey, value in metadata.items():
229
227
yield assert_equal, getattr(inputs.traits()[key], metakey), value""" ]
230
- fp .writelines ('\n ' .join (cmd ))
228
+ fp .writelines ('\n ' .join (cmd ) + ' \n ' )
231
229
232
230
for traitname , trait in classinst .input_spec ().traits (transient = None ).items ():
233
231
for key in trait .__dict__ :
@@ -244,6 +242,32 @@ def test_specs(self, uri):
244
242
245
243
if not classinst .output_spec :
246
244
continue
245
+
246
+ with open (testfile , 'at' ) as fp :
247
+ cmd = ['def test_%s_outputs():' % c ]
248
+ input_fields = ''
249
+ for traitname , trait in classinst .output_spec ().traits (transient = None ).items ():
250
+ input_fields += '%s=dict(' % traitname
251
+ for key , value in trait .__dict__ .items ():
252
+ if key in in_built or key == 'desc' :
253
+ continue
254
+ if isinstance (value , basestring ):
255
+ quote = "'"
256
+ if "'" in value :
257
+ quote = '"'
258
+ input_fields += "%s=%s%s%s,\n " % (key , quote ,
259
+ value , quote )
260
+ else :
261
+ input_fields += "%s=%s,\n " % (key , value )
262
+ input_fields += '),\n '
263
+ cmd += [' output_map = dict(%s)' % input_fields ]
264
+ cmd += [' outputs = %s.output_spec()' % c ]
265
+ cmd += ["""
266
+ for key, metadata in output_map.items():
267
+ for metakey, value in metadata.items():
268
+ yield assert_equal, getattr(outputs.traits()[key], metakey), value""" ]
269
+ fp .writelines ('\n ' .join (cmd ) + '\n ' )
270
+
247
271
for traitname , trait in classinst .output_spec ().traits (transient = None ).items ():
248
272
for key in trait .__dict__ :
249
273
if key in in_built :
0 commit comments