Skip to content

Commit d9f346a

Browse files
committed
Merge pull request #564 from satra/fix/testing
FIX: updated testing so that nipype.test(doctests=True) works fine
2 parents 3bf6539 + 3ea1f0c commit d9f346a

File tree

11 files changed

+47
-587
lines changed

11 files changed

+47
-587
lines changed

nipype/__init__.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,40 @@
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+
from .fixes.numpy.testing import nosetester
17+
18+
class _NoseTester(nosetester.NoseTester):
19+
""" Subclass numpy's NoseTester to add doctests by default
20+
"""
21+
22+
def _get_custom_doctester(self):
23+
return None
24+
25+
def test(self, label='fast', verbose=1, extra_argv=['--exe'],
26+
doctests=True, coverage=False):
27+
"""Run the full test suite
28+
29+
Examples
30+
--------
31+
This will run the test suite and stop at the first failing
32+
example
33+
>>> from nipype import test
34+
>>> test(extra_argv=['--exe', '-sx']) #doctest: +SKIP
35+
"""
36+
return super(_NoseTester, self).test(label=label,
37+
verbose=verbose,
38+
extra_argv=extra_argv,
39+
doctests=doctests,
40+
coverage=coverage)
41+
42+
try:
43+
test = _NoseTester(raise_warnings="release").test
44+
except TypeError:
45+
# Older versions of numpy do not have a raise_warnings argument
46+
test = _NoseTester().test
47+
del nosetester
4448

4549

4650
def _test_local_install():

nipype/interfaces/afni/preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ class Allineate(AFNICommand):
11261126
>>> allineate = afni.Allineate()
11271127
>>> allineate.inputs.in_file = 'functional.nii'
11281128
>>> allineate.inputs.out_file= 'functional_allineate.nii'
1129-
>>> allineate.inputs.matrix= 'cmatrix.mat'
1129+
>>> allineate.inputs.in_matrix= 'cmatrix.mat'
11301130
>>> res = allineate.run() # doctest: +SKIP
11311131
11321132
"""

nipype/interfaces/fsl/model.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,12 +1472,9 @@ class Randomise(FSLCommand):
14721472
Example
14731473
-------
14741474
>>> import nipype.interfaces.fsl as fsl
1475-
>>> rand = fsl.Randomise(in_file='allFA.nii', \
1476-
mask = 'mask.nii', \
1477-
tcon='design.con', \
1478-
design_mat='design.mat')
1475+
>>> rand = fsl.Randomise(in_file='allFA.nii', mask = 'mask.nii', tcon='design.con', design_mat='design.mat')
14791476
>>> rand.cmdline
1480-
'randomise -i allFA.nii -o tbss_ -d design.mat -t design.con -m mask.nii'
1477+
'randomise -i allFA.nii -o "tbss_" -d design.mat -t design.con -m mask.nii'
14811478
14821479
"""
14831480

@@ -1536,20 +1533,25 @@ class GLMInputSpec(FSLCommandInputSpec):
15361533
options = traits.String(
15371534
argstr='%s',
15381535
desc = 'fsl_glm options')
1536+
1537+
15391538
class GLMOutputSpec(TraitedSpec):
15401539
out_file = File(
15411540
exists=True,
15421541
desc = 'file or image output')
15431542

1543+
15441544
class GLM(FSLCommand):
15451545
"""
15461546
FSL GLM:
15471547
15481548
Example
15491549
-------
15501550
>>> import nipype.interfaces.fsl as fsl
1551-
>>> glm = fsl.GLM(in_file='functional.nii', design = 'maps.nii')
1551+
>>> glm = fsl.GLM(in_file='functional.nii', design='maps.nii')
15521552
>>> glm.cmdline
1553+
'fsl_glm -d maps.nii -i functional.nii -o functional_glm.txt'
1554+
15531555
"""
15541556
_cmd = 'fsl_glm'
15551557
input_spec = GLMInputSpec
@@ -1560,17 +1562,12 @@ def _list_outputs(self):
15601562
outputs['out_file'] = self.inputs.out_file
15611563
# Generate an out_file if one is not provided
15621564
if not isdefined(outputs['out_file']) and isdefined(self.inputs.in_file):
1563-
ext = Info.output_type_to_ext(self.inputs.output_type)
1564-
if split_filename(self.inputs.in_file)[-1] in Info.ftypes.values():
1565-
ext = '.txt'
1566-
outputs['out_file'] = self._gen_fname(self.inputs.in_file,
1567-
suffix='_glm',
1568-
ext=ext)
1569-
1565+
outputs['out_file'] = os.path.abspath(self._gen_filename('out_file'))
15701566
return outputs
15711567

15721568
def _gen_filename(self, name):
15731569
if name in ('out_file'):
1574-
return self._list_outputs()[name]
1575-
else:
1576-
return None
1570+
from nipype.utils.filemanip import fname_presuffix
1571+
return fname_presuffix(self.inputs.in_file,
1572+
suffix='_glm.txt', use_ext=False)
1573+
return None

nipype/testing/__init__.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212
for running the algorithms in the NIPY library. This file should
1313
import without nose being present on the python path.
1414
15-
Examples
16-
--------
17-
18-
>>> from nipy.testing import funcfile
19-
>>> from nipy.io.api import load_image
20-
>>> img = load_image(funcfile)
21-
>>> img.shape
22-
(17, 21, 3, 20)
23-
2415
"""
2516

2617
import os
@@ -37,11 +28,6 @@
3728
from nose.tools import *
3829
from numpy.testing import *
3930

40-
# Overwrites numpy.testing.Tester
41-
from .nosetester import NipyNoseTester as Tester
42-
test = Tester().test
43-
bench = Tester().bench
44-
4531
from . import decorators as dec
4632
from .utils import skip_if_no_package, package_check
4733

@@ -58,10 +44,3 @@ def example_data(infile='functional.nii'):
5844
raise IOError('%s empty data file does NOT exist'%(outfile))
5945

6046
return outfile
61-
62-
# Allow failed import of nose if not now running tests
63-
try:
64-
from nose.tools import assert_true, assert_false
65-
from lightunit import ParametricTestCase, parametric
66-
except ImportError:
67-
pass

nipype/testing/_paramtestpy2.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

nipype/testing/_paramtestpy3.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

nipype/testing/data/maps.nii

Whitespace-only changes.

0 commit comments

Comments
 (0)