Skip to content

Commit

Permalink
add test to catch case where optional output-file is passed False to …
Browse files Browse the repository at this point in the history
…disable it
  • Loading branch information
tclose committed Sep 29, 2023
1 parent bbc2769 commit 810dcd2
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions pydra/engine/tests/test_shelltask.py
Original file line number Diff line number Diff line change
Expand Up @@ -4347,7 +4347,7 @@ def change_name(file):
# res = shelly(plugin="cf")


def test_shell_cmd_optional_output_file(tmp_path):
def test_shell_cmd_optional_output_file1(tmp_path):
"""
Test to see that 'unused' doesn't complain about not having an output passed to it
"""
Expand Down Expand Up @@ -4395,7 +4395,52 @@ def test_shell_cmd_optional_output_file(tmp_path):
file1 = tmp_path / "file1.txt"
file1.write_text("foo")
result = my_cp(input=file1, unused=False)
assert result.output.output.read_text() == "foo"
assert result.output.output.fspath.read_text() == "foo"


def test_shell_cmd_optional_output_file2(tmp_path):
"""
Test to see that 'unused' doesn't complain about not having an output passed to it
"""
my_cp_spec = SpecInfo(
name="Input",
fields=[
(
"input",
attr.ib(
type=File, metadata={"argstr": "", "help_string": "input file"}
),
),
(
"output",
attr.ib(
type=ty.Union[Path, bool],
default=False,
metadata={
"argstr": "",
"output_file_template": "out.txt",
"help_string": "dummy output",
},
),
),
],
bases=(ShellSpec,),
)

my_cp = ShellCommandTask(
name="my_cp",
executable="cp",
input_spec=my_cp_spec,
)
file1 = tmp_path / "file1.txt"
file1.write_text("foo")
result = my_cp(input=file1, output=True)
assert result.output.output.fspath.read_text() == "foo"

file2 = tmp_path / "file2.txt"
file2.write_text("bar")
with pytest.raises(RuntimeError):
my_cp(input=file2, output=False)


def test_shell_cmd_non_existing_outputs_1(tmp_path):
Expand Down

0 comments on commit 810dcd2

Please sign in to comment.