Skip to content

Commit fb2b997

Browse files
committed
added test for output_file_template with booleans
1 parent 7f14e98 commit fb2b997

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

pydra/engine/tests/test_helpers_file.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import typing as ty
22
import sys
33
from pathlib import Path
4+
import attr
45
import pytest
56
from fileformats.generic import File
7+
from ..specs import SpecInfo, ShellSpec
8+
from ..task import ShellCommandTask
69
from ..helpers_file import (
710
ensure_list,
811
MountIndentifier,
@@ -343,3 +346,55 @@ def test_cifs_check():
343346
with MountIndentifier.patch_table(fake_table):
344347
for target, expected in cifs_targets:
345348
assert MountIndentifier.on_cifs(target) is expected
349+
350+
351+
def test_output_template(tmp_path):
352+
filename = str(tmp_path / "file.txt")
353+
with open(filename, "w") as f:
354+
f.write("hello from pydra")
355+
in_file = File(filename)
356+
357+
my_input_spec = SpecInfo(
358+
name="Input",
359+
fields=[
360+
(
361+
"in_file",
362+
attr.ib(
363+
type=File,
364+
metadata={
365+
"mandatory": True,
366+
"position": 1,
367+
"argstr": "",
368+
"help_string": "input file",
369+
},
370+
),
371+
),
372+
(
373+
"optional",
374+
attr.ib(
375+
type=ty.Union[Path, bool],
376+
default=False,
377+
metadata={
378+
"position": 2,
379+
"argstr": "--opt",
380+
"output_file_template": "{in_file}.out",
381+
"help_string": "optional file output",
382+
},
383+
),
384+
),
385+
],
386+
bases=(ShellSpec,),
387+
)
388+
389+
class MyCommand(ShellCommandTask):
390+
executable = "my"
391+
input_spec = my_input_spec
392+
393+
task = MyCommand(in_file=filename)
394+
assert task.cmdline == f"my {filename}"
395+
task.inputs.optional = True
396+
assert task.cmdline == f"my {filename} --opt {task.output_dir}/file.out"
397+
task.inputs.optional = False
398+
assert task.cmdline == f"my {filename}"
399+
task.inputs.optional = "custom-file-out.txt"
400+
assert task.cmdline == f"my {filename} --opt custom-file-out.txt"

0 commit comments

Comments
 (0)