@@ -190,11 +190,44 @@ def test_specs(self, uri):
190
190
warnings .simplefilter ("ignore" )
191
191
classinst = sys .modules [uri ].__dict__ [c ]
192
192
except Exception as inst :
193
- print inst
194
193
continue
195
194
196
195
if not issubclass (classinst , BaseInterface ):
197
196
continue
197
+ #print uri, c, uri_short
198
+ testdir = os .path .join (* (uri .split ('.' )[:- 1 ] + ['tests' ]))
199
+ if not os .path .exists (testdir ):
200
+ os .makedirs (testdir )
201
+ #print testdir
202
+ testfile = os .path .join (testdir , 'test_auto_%s.py' % c )
203
+
204
+ with open (testfile , 'wt' ) as fp :
205
+ cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT' ,
206
+ 'from nipype.testing import assert_equal' ,
207
+ 'from %s import %s' % (uri , c ),
208
+ 'def test_%s():' % c ]
209
+ input_fields = ''
210
+ for traitname , trait in classinst .input_spec ().traits (transient = None ).items ():
211
+ input_fields += '%s=dict(' % traitname
212
+ for key , value in trait .__dict__ .items ():
213
+ if key in in_built or key == 'desc' :
214
+ continue
215
+ if isinstance (value , basestring ):
216
+ quote = "'"
217
+ if "'" in value :
218
+ quote = '"'
219
+ input_fields += "%s=%s%s%s,\n " % (key , quote ,
220
+ value , quote )
221
+ else :
222
+ input_fields += "%s=%s,\n " % (key , value )
223
+ input_fields += '),\n '
224
+ cmd += [' input_map = dict(%s)' % input_fields ]
225
+ cmd += [' inputs = %s.input_spec()' % c ]
226
+ cmd += ["""
227
+ for key, metadata in input_map.items():
228
+ for metakey, value in metadata.items():
229
+ yield assert_equal, getattr(inputs.traits()[key], metakey), value""" ]
230
+ fp .writelines ('\n ' .join (cmd ))
198
231
199
232
for traitname , trait in classinst .input_spec ().traits (transient = None ).items ():
200
233
for key in trait .__dict__ :
0 commit comments