@@ -186,11 +186,37 @@ def test_specs(self, uri):
186
186
bad_specs = []
187
187
for c in classes :
188
188
__import__ (uri )
189
+ pkg_check = None
189
190
try :
190
191
with warnings .catch_warnings ():
191
192
warnings .simplefilter ("ignore" )
192
193
classinst = sys .modules [uri ].__dict__ [c ]
194
+ pkg_name = uri .split ('.' )[2 ]
195
+ have_pkg = 'have_%s' % pkg_name
196
+ no_pkg = 'no_%s' % pkg_name
197
+ base_uri = '.' .join (uri .split ('.' )[:3 ])
198
+ if have_pkg in sys .modules [uri ].__dict__ :
199
+ pkg_check = True
200
+ pkg_check_uri = uri
201
+ test_func = have_pkg
202
+ test_name = '@skipif(%s==False)' % have_pkg
203
+ if no_pkg in sys .modules [uri ].__dict__ :
204
+ pkg_check = True
205
+ pkg_check_uri = uri
206
+ test_func = no_pkg
207
+ test_name = '@skipif(%s)' % no_pkg
208
+ if have_pkg in sys .modules [base_uri ].__dict__ :
209
+ pkg_check = True
210
+ pkg_check_uri = base_uri
211
+ test_func = have_pkg
212
+ test_name = '@skipif(%s==False)' % have_pkg
213
+ if no_pkg in sys .modules [base_uri ].__dict__ :
214
+ pkg_check = True
215
+ pkg_check_uri = base_uri
216
+ test_func = no_pkg
217
+ test_name = '@skipif(%s)' % no_pkg
193
218
except Exception as inst :
219
+ print inst
194
220
continue
195
221
196
222
if not issubclass (classinst , BaseInterface ):
@@ -208,8 +234,13 @@ def test_specs(self, uri):
208
234
cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT' ,
209
235
'from nipype.testing import assert_equal' ,
210
236
'from %s import %s' % (uri , c ),
211
- '' ,
212
- 'def test_%s_inputs():' % c ]
237
+ '' ]
238
+ if pkg_check :
239
+ cmd .append ('from nipype.testing import skipif' )
240
+ cmd .append ('from %s import %s' % (pkg_check_uri ,
241
+ test_func ))
242
+ cmd .append (test_name )
243
+ cmd .append ('def test_%s_inputs():' % c )
213
244
input_fields = ''
214
245
for traitname , trait in sorted (classinst .input_spec ().traits (transient = None ).items ()):
215
246
input_fields += '%s=dict(' % traitname
@@ -232,6 +263,8 @@ def test_specs(self, uri):
232
263
for metakey, value in metadata.items():
233
264
yield assert_equal, getattr(inputs.traits()[key], metakey), value""" ]
234
265
fp .writelines ('\n ' .join (cmd ) + '\n \n ' )
266
+ else :
267
+ print ('%s has nonautotest' % c )
235
268
236
269
for traitname , trait in sorted (classinst .input_spec ().traits (transient = None ).items ()):
237
270
for key in sorted (trait .__dict__ ):
0 commit comments