Skip to content

Commit c6facea

Browse files
committed
tst: add generation for removing a test when package is not found
1 parent 87a2548 commit c6facea

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

tools/checkspecs.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,37 @@ def test_specs(self, uri):
186186
bad_specs = []
187187
for c in classes:
188188
__import__(uri)
189+
pkg_check = None
189190
try:
190191
with warnings.catch_warnings():
191192
warnings.simplefilter("ignore")
192193
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
193218
except Exception as inst:
219+
print inst
194220
continue
195221

196222
if not issubclass(classinst, BaseInterface):
@@ -208,8 +234,13 @@ def test_specs(self, uri):
208234
cmd = ['# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT',
209235
'from nipype.testing import assert_equal',
210236
'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)
213244
input_fields = ''
214245
for traitname, trait in sorted(classinst.input_spec().traits(transient=None).items()):
215246
input_fields += '%s=dict(' % traitname
@@ -232,6 +263,8 @@ def test_specs(self, uri):
232263
for metakey, value in metadata.items():
233264
yield assert_equal, getattr(inputs.traits()[key], metakey), value"""]
234265
fp.writelines('\n'.join(cmd) + '\n\n')
266+
else:
267+
print('%s has nonautotest' % c)
235268

236269
for traitname, trait in sorted(classinst.input_spec().traits(transient=None).items()):
237270
for key in sorted(trait.__dict__):

0 commit comments

Comments
 (0)