Skip to content

Commit 152a444

Browse files
committed
DOCTEST: De-indent docstrings with testsetup/cleanup blocks
1 parent 6bca398 commit 152a444

File tree

5 files changed

+108
-122
lines changed

5 files changed

+108
-122
lines changed

nipype/interfaces/base/core.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -680,26 +680,24 @@ def _post_run_hook(self, runtime):
680680

681681
class SimpleInterface(BaseInterface):
682682
""" An interface pattern that allows outputs to be set in a dictionary
683-
called ``_results`` that is automatically interpreted by
684-
``_list_outputs()`` to find the outputs.
683+
called ``_results`` that is automatically interpreted by
684+
``_list_outputs()`` to find the outputs.
685685
686-
When implementing ``_run_interface``, set outputs with::
686+
When implementing ``_run_interface``, set outputs with::
687687
688-
self._results[out_name] = out_value
688+
self._results[out_name] = out_value
689689
690-
This can be a way to upgrade a ``Function`` interface to do type checking.
690+
This can be a way to upgrade a ``Function`` interface to do type checking.
691691
692-
Examples
693-
--------
692+
Examples
693+
--------
694694
695-
.. testsetup::
695+
.. testsetup::
696696
697697
>>> from .specs import TraitedSpec
698698
>>> tmp = getfixture('tmpdir')
699699
>>> old = tmp.chdir() # changing to a temporary directory
700700
701-
.. doctest::
702-
703701
>>> def double(x):
704702
... return 2 * x
705703
...
@@ -722,11 +720,10 @@ class SimpleInterface(BaseInterface):
722720
>>> dbl.run().outputs.doubled
723721
4.0
724722
725-
.. testsetup::
723+
.. testcleanup::
726724
727725
>>> os.chdir(old.strpath)
728-
729-
"""
726+
"""
730727

731728
def __init__(self, from_file=None, resource_monitor=None, **inputs):
732729
super(SimpleInterface, self).__init__(

nipype/interfaces/dcm2nii.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,26 @@ class Dcm2niiOutputSpec(TraitedSpec):
103103
class Dcm2nii(CommandLine):
104104
"""Uses MRIcron's dcm2nii to convert dicom files
105105
106-
Examples
107-
========
106+
Examples
107+
========
108108
109-
.. testsetup::
109+
.. testsetup::
110110
111111
>>> tmp = getfixture('tmpdir')
112112
>>> old = tmp.chdir() # changing to a temporary directory
113113
114-
.. doctest::
115-
116-
>>> from nipype.interfaces.dcm2nii import Dcm2nii
117-
>>> converter = Dcm2nii()
118-
>>> converter.inputs.source_names = [os.path.join(datadir, 'functional_1.dcm'), os.path.join(datadir, 'functional_2.dcm')]
119-
>>> converter.inputs.gzip_output = True
120-
>>> converter.inputs.output_dir = '.'
121-
>>> converter.cmdline #doctest: +ELLIPSIS
122-
'dcm2nii -a y -c y -b config.ini -v y -d y -e y -g y -i n -n y -o . -p y -x n -f n ...functional_1.dcm'
114+
>>> from nipype.interfaces.dcm2nii import Dcm2nii
115+
>>> converter = Dcm2nii()
116+
>>> converter.inputs.source_names = [os.path.join(datadir, 'functional_1.dcm'), os.path.join(datadir, 'functional_2.dcm')]
117+
>>> converter.inputs.gzip_output = True
118+
>>> converter.inputs.output_dir = '.'
119+
>>> converter.cmdline #doctest: +ELLIPSIS
120+
'dcm2nii -a y -c y -b config.ini -v y -d y -e y -g y -i n -n y -o . -p y -x n -f n ...functional_1.dcm'
123121
124-
.. testsetup::
122+
.. testcleanup::
125123
126124
>>> os.chdir(old.strpath)
127-
128-
"""
125+
"""
129126

130127
input_spec = Dcm2niiInputSpec
131128
output_spec = Dcm2niiOutputSpec

nipype/interfaces/image.py

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,65 +32,63 @@ class ReorientOutputSpec(TraitedSpec):
3232
class Reorient(SimpleInterface):
3333
"""Conform an image to a given orientation
3434
35-
Flips and reorder the image data array so that the axes match the
36-
directions indicated in ``orientation``.
37-
The default ``RAS`` orientation corresponds to the first axis being ordered
38-
from left to right, the second axis from posterior to anterior, and the
39-
third axis from inferior to superior.
35+
Flips and reorder the image data array so that the axes match the
36+
directions indicated in ``orientation``.
37+
The default ``RAS`` orientation corresponds to the first axis being ordered
38+
from left to right, the second axis from posterior to anterior, and the
39+
third axis from inferior to superior.
4040
41-
For oblique images, the original orientation is considered to be the
42-
closest plumb orientation.
41+
For oblique images, the original orientation is considered to be the
42+
closest plumb orientation.
4343
44-
No resampling is performed, and thus the output image is not de-obliqued
45-
or registered to any other image or template.
44+
No resampling is performed, and thus the output image is not de-obliqued
45+
or registered to any other image or template.
4646
47-
The effective transform is calculated from the original affine matrix to
48-
the reoriented affine matrix.
47+
The effective transform is calculated from the original affine matrix to
48+
the reoriented affine matrix.
4949
50-
Examples
51-
--------
50+
Examples
51+
--------
5252
53-
.. testsetup::
53+
If an image is not reoriented, the original file is not modified
54+
55+
.. testsetup::
5456
5557
>>> def print_affine(matrix):
5658
... print(str(matrix).replace(']', ' ').replace('[', ' '))
5759
58-
.. doctest::
59-
60-
If an image is not reoriented, the original file is not modified
61-
62-
>>> import numpy as np
63-
>>> from nipype.interfaces.image import Reorient
64-
>>> reorient = Reorient(orientation='LPS')
65-
>>> reorient.inputs.in_file = 'segmentation0.nii.gz'
66-
>>> res = reorient.run()
67-
>>> res.outputs.out_file
68-
'segmentation0.nii.gz'
69-
70-
>>> print_affine(np.loadtxt(res.outputs.transform))
71-
1. 0. 0. 0.
72-
0. 1. 0. 0.
73-
0. 0. 1. 0.
74-
0. 0. 0. 1.
75-
76-
>>> reorient.inputs.orientation = 'RAS'
77-
>>> res = reorient.run()
78-
>>> res.outputs.out_file # doctest: +ELLIPSIS
79-
'.../segmentation0_ras.nii.gz'
80-
81-
>>> print_affine(np.loadtxt(res.outputs.transform))
82-
-1. 0. 0. 60.
83-
0. -1. 0. 72.
84-
0. 0. 1. 0.
85-
0. 0. 0. 1.
86-
87-
.. testcleanup::
88-
89-
>>> import os
90-
>>> os.unlink(res.outputs.out_file)
91-
>>> os.unlink(res.outputs.transform)
92-
93-
"""
60+
>>> import numpy as np
61+
>>> from nipype.interfaces.image import Reorient
62+
>>> reorient = Reorient(orientation='LPS')
63+
>>> reorient.inputs.in_file = 'segmentation0.nii.gz'
64+
>>> res = reorient.run()
65+
>>> res.outputs.out_file
66+
'segmentation0.nii.gz'
67+
68+
>>> print_affine(np.loadtxt(res.outputs.transform))
69+
1. 0. 0. 0.
70+
0. 1. 0. 0.
71+
0. 0. 1. 0.
72+
0. 0. 0. 1.
73+
74+
>>> reorient.inputs.orientation = 'RAS'
75+
>>> res = reorient.run()
76+
>>> res.outputs.out_file # doctest: +ELLIPSIS
77+
'.../segmentation0_ras.nii.gz'
78+
79+
>>> print_affine(np.loadtxt(res.outputs.transform))
80+
-1. 0. 0. 60.
81+
0. -1. 0. 72.
82+
0. 0. 1. 0.
83+
0. 0. 0. 1.
84+
85+
.. testcleanup::
86+
87+
>>> import os
88+
>>> os.unlink(res.outputs.out_file)
89+
>>> os.unlink(res.outputs.transform)
90+
91+
"""
9492
input_spec = ReorientInputSpec
9593
output_spec = ReorientOutputSpec
9694

nipype/interfaces/io.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,36 +2579,33 @@ class JSONFileGrabberInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
25792579

25802580
class JSONFileGrabber(IOBase):
25812581
"""
2582-
Datagrabber interface that loads a json file and generates an output for
2583-
every first-level object
2582+
Datagrabber interface that loads a json file and generates an output for
2583+
every first-level object
25842584
2585-
Example
2586-
-------
2585+
Example
2586+
-------
25872587
2588-
.. testsetup::
2588+
.. testsetup::
25892589
25902590
>>> tmp = getfixture('tmpdir')
25912591
>>> old = tmp.chdir() # changing to a temporary directory
25922592
2593-
.. doctest::
2593+
>>> import pprint
2594+
>>> from nipype.interfaces.io import JSONFileGrabber
2595+
>>> jsonSource = JSONFileGrabber()
2596+
>>> jsonSource.inputs.defaults = {'param1': 'overrideMe', 'param3': 1.0}
2597+
>>> res = jsonSource.run()
2598+
>>> pprint.pprint(res.outputs.get())
2599+
{'param1': 'overrideMe', 'param3': 1.0}
2600+
>>> jsonSource.inputs.in_file = os.path.join(datadir, 'jsongrabber.txt')
2601+
>>> res = jsonSource.run()
2602+
>>> pprint.pprint(res.outputs.get()) # doctest:, +ELLIPSIS
2603+
{'param1': 'exampleStr', 'param2': 4, 'param3': 1.0}
25942604
2595-
>>> import pprint
2596-
>>> from nipype.interfaces.io import JSONFileGrabber
2597-
>>> jsonSource = JSONFileGrabber()
2598-
>>> jsonSource.inputs.defaults = {'param1': 'overrideMe', 'param3': 1.0}
2599-
>>> res = jsonSource.run()
2600-
>>> pprint.pprint(res.outputs.get())
2601-
{'param1': 'overrideMe', 'param3': 1.0}
2602-
>>> jsonSource.inputs.in_file = os.path.join(datadir, 'jsongrabber.txt')
2603-
>>> res = jsonSource.run()
2604-
>>> pprint.pprint(res.outputs.get()) # doctest:, +ELLIPSIS
2605-
{'param1': 'exampleStr', 'param2': 4, 'param3': 1.0}
2606-
2607-
.. testsetup::
2605+
.. testcleanup::
26082606
26092607
>>> os.chdir(old.strpath)
2610-
2611-
"""
2608+
"""
26122609
input_spec = JSONFileGrabberInputSpec
26132610
output_spec = DynamicTraitedSpec
26142611
_always_run = True

nipype/interfaces/niftyreg/regutils.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -437,40 +437,37 @@ class RegAverageOutputSpec(TraitedSpec):
437437
class RegAverage(NiftyRegCommand):
438438
"""Interface for executable reg_average from NiftyReg platform.
439439
440-
Compute average matrix or image from a list of matrices or image.
441-
The tool can be use to resample images given input transformation
442-
parametrisation as well as to demean transformations in Euclidean or
443-
log-Euclidean space.
440+
Compute average matrix or image from a list of matrices or image.
441+
The tool can be use to resample images given input transformation
442+
parametrisation as well as to demean transformations in Euclidean or
443+
log-Euclidean space.
444444
445-
This interface is different than the others in the way that the options
446-
will be written in a command file that is given as a parameter.
445+
This interface is different than the others in the way that the options
446+
will be written in a command file that is given as a parameter.
447447
448-
`Source code <https://cmiclab.cs.ucl.ac.uk/mmodat/niftyreg>`_
448+
`Source code <https://cmiclab.cs.ucl.ac.uk/mmodat/niftyreg>`_
449449
450-
Examples
451-
--------
450+
Examples
451+
--------
452452
453-
.. testsetup::
453+
.. testsetup::
454454
455455
>>> tmp = getfixture('tmpdir')
456456
>>> old = tmp.chdir() # changing to temporary file
457457
458-
.. doctest::
458+
>>> from nipype.interfaces import niftyreg
459+
>>> node = niftyreg.RegAverage()
460+
>>> one_file = 'im1.nii'
461+
>>> two_file = 'im2.nii'
462+
>>> three_file = 'im3.nii'
463+
>>> node.inputs.avg_files = [one_file, two_file, three_file]
464+
>>> node.cmdline # doctest: +ELLIPSIS
465+
'reg_average --cmd_file .../reg_average_cmd'
459466
460-
>>> from nipype.interfaces import niftyreg
461-
>>> node = niftyreg.RegAverage()
462-
>>> one_file = 'im1.nii'
463-
>>> two_file = 'im2.nii'
464-
>>> three_file = 'im3.nii'
465-
>>> node.inputs.avg_files = [one_file, two_file, three_file]
466-
>>> node.cmdline # doctest: +ELLIPSIS
467-
'reg_average --cmd_file .../reg_average_cmd'
468-
469-
.. testsetup::
467+
.. testcleanup::
470468
471469
>>> os.chdir(old.strpath)
472-
473-
"""
470+
"""
474471
_cmd = get_custom_path('reg_average')
475472
input_spec = RegAverageInputSpec
476473
output_spec = RegAverageOutputSpec

0 commit comments

Comments
 (0)