Skip to content

Commit 13426a0

Browse files
committed
fix: testing to use numpy tester directly without extensive customization
1 parent 3bf6539 commit 13426a0

File tree

1 file changed

+48
-29
lines changed

1 file changed

+48
-29
lines changed

nipype/__init__.py

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,55 @@
1111
from utils.logger import Logging
1212
logging = Logging(config)
1313

14-
# We require numpy 1.2 for our test suite. If Tester fails to import,
15-
# check the version of numpy the user has and inform them they need to
16-
# upgrade.
17-
import numpy as np
1814
from distutils.version import LooseVersion
19-
if LooseVersion(np.__version__) >= '1.2':
20-
from numpy.testing import Tester
21-
else:
22-
from testing.numpytesting import Tester
23-
24-
25-
class NipypeTester(Tester):
26-
def test(self, label='fast', verbose=1, extra_argv=None,
27-
doctests=False, coverage=False):
28-
# setuptools does a chmod +x on ALL python modules when it
29-
# installs. By default, as a security measure, nose refuses to
30-
# import executable files. To forse nose to execute our tests, we
31-
# must supply the '--exe' flag. List thread on this:
32-
# http://www.mail-archive.com/[email protected]/msg05009.html
33-
if not extra_argv:
34-
extra_argv = ['--exe']
35-
else:
36-
extra_argv.append('--exe')
37-
super(NipypeTester, self).test(label, verbose, extra_argv,
38-
doctests, coverage)
39-
# Grab the docstring from numpy
40-
#test.__doc__ = Tester.test.__doc__
41-
42-
test = NipypeTester().test
43-
bench = NipypeTester().bench
15+
16+
try:
17+
from numpy.testing import nosetester
18+
19+
class _NoseTester(nosetester.NoseTester):
20+
""" Subclass numpy's NoseTester to add doctests by default
21+
"""
22+
23+
def _get_custom_doctester(self):
24+
return None
25+
26+
def prepare_test_args(self, label='fast', verbose=1, extra_argv=None,
27+
doctests=False, coverage=False):
28+
argv, plugins = super(_NoseTester, self).prepare_test_args(label=label,
29+
verbose=verbose,
30+
extra_argv=extra_argv,
31+
doctests=doctests,
32+
coverage=coverage)
33+
if doctests and '--with-numpydoctest' in argv:
34+
numpydocindex = argv.index('--with-numpydoctest')
35+
argv[numpydocindex] = '--with-doctest'
36+
return argv, plugins
37+
38+
def test(self, label='fast', verbose=1, extra_argv=['--exe'],
39+
doctests=True, coverage=False):
40+
"""Run the full test suite
41+
42+
Examples
43+
--------
44+
This will run the test suite and stop at the first failing
45+
example
46+
>>> from nipype import test
47+
>>> test(extra_argv=['--exe', '-sx']) #doctest: +SKIP
48+
"""
49+
return super(_NoseTester, self).test(label=label,
50+
verbose=verbose,
51+
extra_argv=extra_argv,
52+
doctests=doctests,
53+
coverage=coverage)
54+
55+
try:
56+
test = _NoseTester(raise_warnings="release").test
57+
except TypeError:
58+
# Older versions of numpy do not have a raise_warnings argument
59+
test = _NoseTester().test
60+
del nosetester
61+
except:
62+
pass
4463

4564

4665
def _test_local_install():

0 commit comments

Comments
 (0)