Skip to content

Commit 64214b4

Browse files
committed
enh: modified checkspecs to write input spec tests
1 parent 45ef771 commit 64214b4

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

tools/checkspecs.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,44 @@ def test_specs(self, uri):
190190
warnings.simplefilter("ignore")
191191
classinst = sys.modules[uri].__dict__[c]
192192
except Exception as inst:
193-
print inst
194193
continue
195194

196195
if not issubclass(classinst, BaseInterface):
197196
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))
198231

199232
for traitname, trait in classinst.input_spec().traits(transient=None).items():
200233
for key in trait.__dict__:

0 commit comments

Comments
 (0)