Skip to content

Commit 087f5c3

Browse files
committed
enh: add test on LiterateWorkflow
1 parent e6e542f commit 087f5c3

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

niworkflows/engine/tests/__init__.py

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Test the LiterateWorkflow."""
2+
from nipype.pipeline.engine import Node
3+
from nipype.interfaces import afni, utility as niu
4+
from ..workflows import LiterateWorkflow as Workflow
5+
6+
7+
def _reorient_wf(name='ReorientWorkflow'):
8+
"""A workflow to reorient images to 'RPI' orientation."""
9+
workflow = Workflow(name=name)
10+
workflow.__desc__ = "Inner workflow. "
11+
inputnode = Node(niu.IdentityInterface(fields=['in_file']),
12+
name='inputnode')
13+
outputnode = Node(niu.IdentityInterface(
14+
fields=['out_file']), name='outputnode')
15+
deoblique = Node(afni.Refit(deoblique=True), name='deoblique')
16+
reorient = Node(afni.Resample(
17+
orientation='RPI', outputtype='NIFTI_GZ'), name='reorient')
18+
workflow.connect([
19+
(inputnode, deoblique, [('in_file', 'in_file')]),
20+
(deoblique, reorient, [('out_file', 'in_file')]),
21+
(reorient, outputnode, [('out_file', 'out_file')])
22+
])
23+
return workflow
24+
25+
26+
def test_boilerplate():
27+
"""Check the boilerplate is generated."""
28+
29+
workflow = Workflow(name='test')
30+
workflow.__desc__ = "Outer workflow. "
31+
workflow.__postdesc__ = "Outer workflow (postdesc)."
32+
33+
inputnode = Node(niu.IdentityInterface(fields=['in_file']),
34+
name='inputnode')
35+
inner = _reorient_wf()
36+
37+
workflow.connect([
38+
(inputnode, inner, [('in_file', 'inputnode.in_file')]),
39+
])
40+
41+
assert workflow.visit_desc() == "Outer workflow. Inner workflow. Outer workflow (postdesc)."

niworkflows/engine/workflows.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# -*- coding: utf-8 -*-
21
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
32
# vi: set ft=python sts=4 ts=4 sw=4 et:
43
"""
5-
Supercharging Nipype's workflow engine
6-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
Supercharging Nipype's workflow engine.
75
86
Add special features to the Nipype's vanilla workflows
97
"""
@@ -14,23 +12,23 @@ class LiterateWorkflow(pe.Workflow):
1412
"""Controls the setup and execution of a pipeline of processes."""
1513

1614
def __init__(self, name, base_dir=None):
17-
"""Create a workflow object.
15+
"""
16+
Create a workflow object.
17+
1818
Parameters
1919
----------
20-
name : alphanumeric string
20+
name : alphanumeric :obj:`str`
2121
unique identifier for the workflow
22-
base_dir : string, optional
22+
base_dir : :obj:`str`, optional
2323
path to workflow storage
24+
2425
"""
2526
super(LiterateWorkflow, self).__init__(name, base_dir)
2627
self.__desc__ = None
2728
self.__postdesc__ = None
2829

2930
def visit_desc(self):
30-
"""
31-
Builds a citation boilerplate by visiting all workflows
32-
appending their ``__desc__`` field
33-
"""
31+
"""Build a citation boilerplate by visiting all workflows."""
3432
desc = []
3533

3634
if self.__desc__:

0 commit comments

Comments
 (0)