Skip to content

Commit 0086958

Browse files
committed
enh: modified checkspecs to write output spec tests
1 parent 64214b4 commit 0086958

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

tools/checkspecs.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,16 @@ def test_specs(self, uri):
194194

195195
if not issubclass(classinst, BaseInterface):
196196
continue
197-
#print uri, c, uri_short
198197
testdir = os.path.join(*(uri.split('.')[:-1] + ['tests']))
199198
if not os.path.exists(testdir):
200199
os.makedirs(testdir)
201-
#print testdir
202200
testfile = os.path.join(testdir, 'test_auto_%s.py' % c)
203201

204202
with open(testfile, 'wt') as fp:
205203
cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT',
206204
'from nipype.testing import assert_equal',
207205
'from %s import %s' % (uri, c),
208-
'def test_%s():' % c]
206+
'def test_%s_inputs():' % c]
209207
input_fields = ''
210208
for traitname, trait in classinst.input_spec().traits(transient=None).items():
211209
input_fields += '%s=dict(' % traitname
@@ -227,7 +225,7 @@ def test_specs(self, uri):
227225
for key, metadata in input_map.items():
228226
for metakey, value in metadata.items():
229227
yield assert_equal, getattr(inputs.traits()[key], metakey), value"""]
230-
fp.writelines('\n'.join(cmd))
228+
fp.writelines('\n'.join(cmd) + '\n')
231229

232230
for traitname, trait in classinst.input_spec().traits(transient=None).items():
233231
for key in trait.__dict__:
@@ -244,6 +242,32 @@ def test_specs(self, uri):
244242

245243
if not classinst.output_spec:
246244
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+
247271
for traitname, trait in classinst.output_spec().traits(transient=None).items():
248272
for key in trait.__dict__:
249273
if key in in_built:

0 commit comments

Comments
 (0)