@@ -197,35 +197,39 @@ def test_specs(self, uri):
197
197
testdir = os .path .join (* (uri .split ('.' )[:- 1 ] + ['tests' ]))
198
198
if not os .path .exists (testdir ):
199
199
os .makedirs (testdir )
200
+ nonautotest = os .path .join (testdir , 'test_%s.py' % c )
200
201
testfile = os .path .join (testdir , 'test_auto_%s.py' % c )
201
-
202
- with open (testfile , 'wt' ) as fp :
203
- cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT' ,
204
- 'from nipype.testing import assert_equal' ,
205
- 'from %s import %s' % (uri , c ),
206
- 'def test_%s_inputs():' % c ]
207
- input_fields = ''
208
- for traitname , trait in classinst .input_spec ().traits (transient = None ).items ():
209
- input_fields += '%s=dict(' % traitname
210
- for key , value in trait .__dict__ .items ():
211
- if key in in_built or key == 'desc' :
212
- continue
213
- if isinstance (value , basestring ):
214
- quote = "'"
215
- if "'" in value :
216
- quote = '"'
217
- input_fields += "%s=%s%s%s,\n " % (key , quote ,
218
- value , quote )
219
- else :
220
- input_fields += "%s=%s,\n " % (key , value )
221
- input_fields += '),\n '
222
- cmd += [' input_map = dict(%s)' % input_fields ]
223
- cmd += [' inputs = %s.input_spec()' % c ]
224
- cmd += ["""
202
+ if os .path .exists (testfile ):
203
+ os .unlink (testfile )
204
+
205
+ if not os .path .exists (nonautotest ):
206
+ with open (testfile , 'wt' ) as fp :
207
+ cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT' ,
208
+ 'from nipype.testing import assert_equal' ,
209
+ 'from %s import %s' % (uri , c ),
210
+ 'def test_%s_inputs():' % c ]
211
+ input_fields = ''
212
+ for traitname , trait in classinst .input_spec ().traits (transient = None ).items ():
213
+ input_fields += '%s=dict(' % traitname
214
+ for key , value in trait .__dict__ .items ():
215
+ if key in in_built or key == 'desc' :
216
+ continue
217
+ if isinstance (value , basestring ):
218
+ quote = "'"
219
+ if "'" in value :
220
+ quote = '"'
221
+ input_fields += "%s=%s%s%s,\n " % (key , quote ,
222
+ value , quote )
223
+ else :
224
+ input_fields += "%s=%s,\n " % (key , value )
225
+ input_fields += '),\n '
226
+ cmd += [' input_map = dict(%s)' % input_fields ]
227
+ cmd += [' inputs = %s.input_spec()' % c ]
228
+ cmd += ["""
225
229
for key, metadata in input_map.items():
226
230
for metakey, value in metadata.items():
227
231
yield assert_equal, getattr(inputs.traits()[key], metakey), value""" ]
228
- fp .writelines ('\n ' .join (cmd ) + '\n ' )
232
+ fp .writelines ('\n ' .join (cmd ) + '\n ' )
229
233
230
234
for traitname , trait in classinst .input_spec ().traits (transient = None ).items ():
231
235
for key in trait .__dict__ :
@@ -243,30 +247,31 @@ def test_specs(self, uri):
243
247
if not classinst .output_spec :
244
248
continue
245
249
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 += ["""
250
+ if not os .path .exists (nonautotest ):
251
+ with open (testfile , 'at' ) as fp :
252
+ cmd = ['def test_%s_outputs():' % c ]
253
+ input_fields = ''
254
+ for traitname , trait in classinst .output_spec ().traits (transient = None ).items ():
255
+ input_fields += '%s=dict(' % traitname
256
+ for key , value in trait .__dict__ .items ():
257
+ if key in in_built or key == 'desc' :
258
+ continue
259
+ if isinstance (value , basestring ):
260
+ quote = "'"
261
+ if "'" in value :
262
+ quote = '"'
263
+ input_fields += "%s=%s%s%s,\n " % (key , quote ,
264
+ value , quote )
265
+ else :
266
+ input_fields += "%s=%s,\n " % (key , value )
267
+ input_fields += '),\n '
268
+ cmd += [' output_map = dict(%s)' % input_fields ]
269
+ cmd += [' outputs = %s.output_spec()' % c ]
270
+ cmd += ["""
266
271
for key, metadata in output_map.items():
267
272
for metakey, value in metadata.items():
268
273
yield assert_equal, getattr(outputs.traits()[key], metakey), value""" ]
269
- fp .writelines ('\n ' .join (cmd ) + '\n ' )
274
+ fp .writelines ('\n ' .join (cmd ) + '\n ' )
270
275
271
276
for traitname , trait in classinst .output_spec ().traits (transient = None ).items ():
272
277
for key in trait .__dict__ :
0 commit comments