Skip to content

Commit

Permalink
Merge pull request #379 from djarecka/fix/template_formatting
Browse files Browse the repository at this point in the history
fixing template formatting
  • Loading branch information
djarecka authored Nov 11, 2020
2 parents e168af4 + 937172f commit 678924e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
8 changes: 6 additions & 2 deletions pydra/engine/helpers_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,12 @@ def _template_formatting(template, inputs_dict, keep_extension=True):
fld_value = inputs_dict[fld_name]
if fld_value is attr.NOTHING:
return attr.NOTHING
fld_value = str(fld_value) # in case it's a path
filename, *ext = fld_value.split(".", maxsplit=1)
fld_value_parent = Path(fld_value).parent
fld_value_name = Path(fld_value).name

name, *ext = fld_value_name.split(".", maxsplit=1)
filename = str(fld_value_parent / name)

# if keep_extension is False, the extensions are removed
if keep_extension is False:
ext = []
Expand Down
52 changes: 50 additions & 2 deletions pydra/engine/tests/test_shelltask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,56 @@ def test_shell_cmd_inputspec_9(tmpdir, plugin, results_function):
assert shelly.output_dir == res.output.file_copy.parent


@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
@pytest.mark.parametrize("results_function", [result_no_submitter])
def test_shell_cmd_inputspec_9a(tmpdir, plugin, results_function):
"""
providing output name using input_spec (output_file_template in metadata),
the template has a suffix, the extension of the file will be moved to the end
the change: input file has directory with a dot
"""
cmd = "cp"
file = tmpdir.mkdir("data.inp").join("file.txt")
file.write("content")

my_input_spec = SpecInfo(
name="Input",
fields=[
(
"file_orig",
attr.ib(
type=File,
metadata={"position": 2, "help_string": "new file", "argstr": ""},
),
),
(
"file_copy",
attr.ib(
type=str,
metadata={
"output_file_template": "{file_orig}_copy",
"help_string": "output file",
"argstr": "",
},
),
),
],
bases=(ShellSpec,),
)

shelly = ShellCommandTask(
name="shelly", executable=cmd, input_spec=my_input_spec, file_orig=file
)

res = results_function(shelly, plugin)
assert res.output.stdout == ""
assert res.output.file_copy.exists()
assert res.output.file_copy.name == "file_copy.txt"
# checking if it's created in a good place
assert shelly.output_dir == res.output.file_copy.parent


@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
def test_shell_cmd_inputspec_9b(tmpdir, plugin, results_function):
"""
providing output name using input_spec (output_file_template in metadata)
and the keep_extension is set to False, so the extension is removed completely.
Expand Down Expand Up @@ -1263,7 +1311,7 @@ def test_shell_cmd_inputspec_9a(tmpdir, plugin, results_function):


@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
def test_shell_cmd_inputspec_9b(tmpdir, plugin, results_function):
def test_shell_cmd_inputspec_9c(tmpdir, plugin, results_function):
"""
providing output name using input_spec (output_file_template in metadata)
and the keep_extension is set to False, so the extension is removed completely,
Expand Down

0 comments on commit 678924e

Please sign in to comment.