Skip to content

Commit 46a6e9a

Browse files
committed
MNT: Add test case for output spec with staticmethod callable
1 parent 9473758 commit 46a6e9a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pydra/engine/tests/test_shelltask.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,6 +2928,35 @@ def gather_output(executable, output_dir, ble):
29282928
shelly()
29292929

29302930

2931+
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
2932+
def test_shell_cmd_outputspec_5c(plugin, results_function):
2933+
"""
2934+
Customised output spec defined as a class,
2935+
using a static function to collect output files.
2936+
"""
2937+
2938+
@attr.s(kw_only=True)
2939+
class MyOutputSpec(ShellOutSpec):
2940+
@staticmethod
2941+
def gather_output(executable, output_dir):
2942+
files = executable[1:]
2943+
return [Path(output_dir) / file for file in files]
2944+
2945+
newfile: MultiOutputFile = attr.ib(metadata={"callable": gather_output})
2946+
2947+
shelly = ShellCommandTask(
2948+
name="shelly",
2949+
executable=["touch", "newfile_tmp1.txt", "newfile_tmp2.txt"],
2950+
output_spec=SpecInfo(name="Output", bases=(MyOutputSpec,)),
2951+
)
2952+
2953+
res = results_function(shelly, plugin)
2954+
assert res.output.stdout == ""
2955+
# newfile is a list
2956+
assert len(res.output.newfile) == 2
2957+
assert all([file.exists for file in res.output.newfile])
2958+
2959+
29312960
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
29322961
def test_shell_cmd_outputspec_6(plugin, results_function, tmpdir):
29332962
"""

0 commit comments

Comments
 (0)