From 810dcd2fce1e776da631baf25b461546874f6f0e Mon Sep 17 00:00:00 2001 From: Tom Close Date: Fri, 29 Sep 2023 10:34:54 +1000 Subject: [PATCH] add test to catch case where optional output-file is passed False to disable it --- pydra/engine/tests/test_shelltask.py | 49 ++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/pydra/engine/tests/test_shelltask.py b/pydra/engine/tests/test_shelltask.py index da1821bbd4..af696ec478 100644 --- a/pydra/engine/tests/test_shelltask.py +++ b/pydra/engine/tests/test_shelltask.py @@ -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 """ @@ -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):