Skip to content

Commit 8f2e841

Browse files
committed
small changes in bosh input/output specs; adding tests with workflows
1 parent 00c668d commit 8f2e841

File tree

4 files changed

+108
-19
lines changed

4 files changed

+108
-19
lines changed

pydra/engine/boutiques.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _prepare_input_spec(self):
130130
tp = ty.List[tp]
131131

132132
mdata = {
133-
"help_string": input["description"],
133+
"help_string": input.get("description", None) or input["name"],
134134
"mandatory": not input["optional"],
135135
"argstr": input.get("command-line-flag", None),
136136
}
@@ -152,7 +152,7 @@ def _prepare_output_spec(self):
152152
output["path-template"],
153153
)
154154
mdata = {
155-
"help_string": output["description"],
155+
"help_string": output.get("description", None) or output["name"],
156156
"mandatory": not output["optional"],
157157
"output_file_template": path_template,
158158
}
@@ -181,6 +181,7 @@ def _input_file(self, state_ind, ind=None):
181181
# adding to the json file if specified by the user
182182
if value is not attr.NOTHING and value != "NOTHING":
183183
if is_local_file(f):
184+
value = Path(value)
184185
self.bindings.extend(["-v", f"{value.parent}:{value.parent}:ro"])
185186
value = str(value)
186187

pydra/engine/tests/test_boutiques.py

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,37 @@
33
from pathlib import Path
44
import pytest
55

6+
from ..core import Workflow
7+
from ..submitter import Submitter
68
from ..boutiques import BoshTask
9+
from .utils import result_no_submitter, result_submitter
710

811
need_bosh_docker = pytest.mark.skipif(
912
shutil.which("docker") is None
1013
or sp.call(["docker", "info"] or sp.call(["bosh", "version"])),
1114
reason="requires docker and bosh",
1215
)
1316

17+
if bool(shutil.which("sbatch")):
18+
Plugins = ["cf", "slurm"]
19+
else:
20+
Plugins = ["cf"]
21+
22+
Infile = Path(__file__).resolve().parent / "data_tests" / "test.nii.gz"
23+
1424

1525
@need_bosh_docker
1626
@pytest.mark.parametrize(
1727
"maskfile", ["test_brain.nii.gz", "test_brain", "test_brain.nii"]
1828
)
19-
def test_boutiques_1(maskfile):
29+
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
30+
@pytest.mark.parametrize("plugin", Plugins)
31+
def test_boutiques_1(maskfile, plugin, results_function):
32+
""" simple task to run fsl.bet using BoshTask"""
2033
btask = BoshTask(name="NA", zenodo="zenodo.1482743")
21-
btask.inputs.infile = Path(__file__).resolve().parent / "data_tests" / "test.nii.gz"
34+
btask.inputs.infile = Infile
2235
btask.inputs.maskfile = maskfile
23-
res = btask()
36+
res = results_function(btask, plugin)
2437

2538
assert res.output.return_code == 0
2639

@@ -30,3 +43,76 @@ def test_boutiques_1(maskfile):
3043
# other files should also have proper names, but they do not exist
3144
assert res.output.out_outskin_off.name == "test_brain_outskin_mesh.off"
3245
assert not res.output.out_outskin_off.exists()
46+
47+
48+
@need_bosh_docker
49+
@pytest.mark.parametrize(
50+
"maskfile", ["test_brain.nii.gz", "test_brain", "test_brain.nii"]
51+
)
52+
@pytest.mark.parametrize("plugin", Plugins)
53+
def test_boutiques_wf_1(maskfile, plugin):
54+
""" wf with one task that runs fsl.bet using BoshTask"""
55+
wf = Workflow(name="wf", input_spec=["maskfile", "infile"])
56+
wf.inputs.maskfile = maskfile
57+
wf.inputs.infile = Infile
58+
59+
wf.add(
60+
BoshTask(
61+
name="bet",
62+
zenodo="zenodo.1482743",
63+
infile=wf.lzin.infile,
64+
maskfile=wf.lzin.maskfile,
65+
)
66+
)
67+
68+
wf.set_output([("outfile", wf.bet.lzout.outfile)])
69+
70+
with Submitter(plugin=plugin) as sub:
71+
wf(submitter=sub)
72+
73+
res = wf.result()
74+
assert res.output.outfile.name == "test_brain.nii.gz"
75+
assert res.output.outfile.exists()
76+
77+
78+
@need_bosh_docker
79+
@pytest.mark.parametrize(
80+
"maskfile", ["test_brain.nii.gz", "test_brain", "test_brain.nii"]
81+
)
82+
@pytest.mark.parametrize("plugin", Plugins)
83+
def test_boutiques_wf_2(maskfile, plugin):
84+
""" wf with two tasks that run fsl.bet and fsl.stats using BoshTask"""
85+
wf = Workflow(name="wf", input_spec=["maskfile", "infile"])
86+
wf.inputs.maskfile = maskfile
87+
wf.inputs.infile = Infile
88+
89+
wf.add(
90+
BoshTask(
91+
name="bet",
92+
zenodo="zenodo.1482743",
93+
infile=wf.lzin.infile,
94+
maskfile=wf.lzin.maskfile,
95+
)
96+
)
97+
wf.add(
98+
BoshTask(
99+
name="stat",
100+
zenodo="zenodo.3240521",
101+
input_file=wf.bet.lzout.outfile,
102+
v=True,
103+
)
104+
)
105+
106+
wf.set_output(
107+
[("outfile_bet", wf.bet.lzout.outfile), ("out_stat", wf.stat.lzout.output)]
108+
)
109+
110+
with Submitter(plugin=plugin) as sub:
111+
wf(submitter=sub)
112+
113+
res = wf.result()
114+
assert res.output.outfile_bet.name == "test_brain.nii.gz"
115+
assert res.output.outfile_bet.exists()
116+
117+
assert res.output.out_stat.name == "output.txt"
118+
assert res.output.out_stat.exists()

pydra/engine/tests/test_shelltask.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,14 @@
1111
from ..submitter import Submitter
1212
from ..core import Workflow
1313
from ..specs import ShellOutSpec, ShellSpec, SpecInfo, File
14+
from .utils import result_no_submitter, result_submitter
1415

1516
if bool(shutil.which("sbatch")):
1617
Plugins = ["cf", "slurm"]
1718
else:
1819
Plugins = ["cf"]
1920

2021

21-
def result_no_submitter(shell_task, plugin=None):
22-
""" helper function to return result when running without submitter """
23-
return shell_task()
24-
25-
26-
def result_submitter(shell_task, plugin):
27-
""" helper function to return result when running with submitter
28-
with specific plugin
29-
"""
30-
with Submitter(plugin=plugin) as sub:
31-
shell_task(submitter=sub)
32-
return shell_task.result()
33-
34-
3522
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
3623
@pytest.mark.parametrize("plugin", Plugins)
3724
def test_shell_cmd_1(plugin, results_function):

pydra/engine/tests/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,25 @@
44
from pathlib import Path
55

66
from ..core import Workflow
7+
from ..submitter import Submitter
78
from ... import mark
89
from ..specs import File
910

1011

12+
def result_no_submitter(shell_task, plugin=None):
13+
""" helper function to return result when running without submitter """
14+
return shell_task()
15+
16+
17+
def result_submitter(shell_task, plugin):
18+
""" helper function to return result when running with submitter
19+
with specific plugin
20+
"""
21+
with Submitter(plugin=plugin) as sub:
22+
shell_task(submitter=sub)
23+
return shell_task.result()
24+
25+
1126
@mark.task
1227
def fun_addtwo(a):
1328
import time

0 commit comments

Comments
 (0)