From 580226d6b384d1cd724a05728a4a2098750651d4 Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Fri, 1 Nov 2013 09:13:45 -0400 Subject: [PATCH] fix: update test generator to take manual edits into account --- tools/checkspecs.py | 97 ++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/tools/checkspecs.py b/tools/checkspecs.py index 4647de75ec..2b5afbc8f1 100644 --- a/tools/checkspecs.py +++ b/tools/checkspecs.py @@ -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__: @@ -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__: