Skip to content

Commit

Permalink
fix: update test generator to take manual edits into account
Browse files Browse the repository at this point in the history
  • Loading branch information
satra committed Nov 1, 2013
1 parent 6d0ecc4 commit 580226d
Showing 1 changed file with 51 additions and 46 deletions.
97 changes: 51 additions & 46 deletions tools/checkspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,35 +197,39 @@ def test_specs(self, uri):
testdir = os.path.join(*(uri.split('.')[:-1] + ['tests']))
if not os.path.exists(testdir):
os.makedirs(testdir)
nonautotest = os.path.join(testdir, 'test_%s.py' % c)
testfile = os.path.join(testdir, 'test_auto_%s.py' % c)

with open(testfile, 'wt') as fp:
cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT',
'from nipype.testing import assert_equal',
'from %s import %s' % (uri, c),
'def test_%s_inputs():' % c]
input_fields = ''
for traitname, trait in classinst.input_spec().traits(transient=None).items():
input_fields += '%s=dict(' % traitname
for key, value in trait.__dict__.items():
if key in in_built or key == 'desc':
continue
if isinstance(value, basestring):
quote = "'"
if "'" in value:
quote = '"'
input_fields += "%s=%s%s%s,\n " % (key, quote,
value, quote)
else:
input_fields += "%s=%s,\n " % (key, value)
input_fields += '),\n '
cmd += [' input_map = dict(%s)' % input_fields]
cmd += [' inputs = %s.input_spec()' % c]
cmd += ["""
if os.path.exists(testfile):
os.unlink(testfile)

if not os.path.exists(nonautotest):
with open(testfile, 'wt') as fp:
cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT',
'from nipype.testing import assert_equal',
'from %s import %s' % (uri, c),
'def test_%s_inputs():' % c]
input_fields = ''
for traitname, trait in classinst.input_spec().traits(transient=None).items():
input_fields += '%s=dict(' % traitname
for key, value in trait.__dict__.items():
if key in in_built or key == 'desc':
continue
if isinstance(value, basestring):
quote = "'"
if "'" in value:
quote = '"'
input_fields += "%s=%s%s%s,\n " % (key, quote,
value, quote)
else:
input_fields += "%s=%s,\n " % (key, value)
input_fields += '),\n '
cmd += [' input_map = dict(%s)' % input_fields]
cmd += [' inputs = %s.input_spec()' % c]
cmd += ["""
for key, metadata in input_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(inputs.traits()[key], metakey), value"""]
fp.writelines('\n'.join(cmd) + '\n')
fp.writelines('\n'.join(cmd) + '\n')

for traitname, trait in classinst.input_spec().traits(transient=None).items():
for key in trait.__dict__:
Expand All @@ -243,30 +247,31 @@ def test_specs(self, uri):
if not classinst.output_spec:
continue

with open(testfile, 'at') as fp:
cmd = ['def test_%s_outputs():' % c]
input_fields = ''
for traitname, trait in classinst.output_spec().traits(transient=None).items():
input_fields += '%s=dict(' % traitname
for key, value in trait.__dict__.items():
if key in in_built or key == 'desc':
continue
if isinstance(value, basestring):
quote = "'"
if "'" in value:
quote = '"'
input_fields += "%s=%s%s%s,\n " % (key, quote,
value, quote)
else:
input_fields += "%s=%s,\n " % (key, value)
input_fields += '),\n '
cmd += [' output_map = dict(%s)' % input_fields]
cmd += [' outputs = %s.output_spec()' % c]
cmd += ["""
if not os.path.exists(nonautotest):
with open(testfile, 'at') as fp:
cmd = ['def test_%s_outputs():' % c]
input_fields = ''
for traitname, trait in classinst.output_spec().traits(transient=None).items():
input_fields += '%s=dict(' % traitname
for key, value in trait.__dict__.items():
if key in in_built or key == 'desc':
continue
if isinstance(value, basestring):
quote = "'"
if "'" in value:
quote = '"'
input_fields += "%s=%s%s%s,\n " % (key, quote,
value, quote)
else:
input_fields += "%s=%s,\n " % (key, value)
input_fields += '),\n '
cmd += [' output_map = dict(%s)' % input_fields]
cmd += [' outputs = %s.output_spec()' % c]
cmd += ["""
for key, metadata in output_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(outputs.traits()[key], metakey), value"""]
fp.writelines('\n'.join(cmd) + '\n')
fp.writelines('\n'.join(cmd) + '\n')

for traitname, trait in classinst.output_spec().traits(transient=None).items():
for key in trait.__dict__:
Expand Down

0 comments on commit 580226d

Please sign in to comment.