Skip to content

Commit 17072ab

Browse files
author
Zach Lindsey
committed
remove stuff form other branch, add string interpolation
1 parent 962f1cd commit 17072ab

File tree

7 files changed

+65
-42
lines changed

7 files changed

+65
-42
lines changed

nipype/interfaces/afni/tests/test_auto_Zeropad.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def test_Zeropad_inputs():
7070
out_file=dict(
7171
argstr="-prefix %s",
7272
extensions=None,
73+
name_template="zeropad",
7374
),
7475
outputtype=dict(),
7576
z=dict(

nipype/interfaces/afni/tests/test_extra_Zeropad.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,3 @@
33
from nipype.interfaces.afni import Zeropad
44
from nipype.testing.fixtures import create_files_in_directory
55

6-
7-
def test_zeropad_handles_outfile_default(create_files_in_directory):
8-
filelist, outdir = create_files_in_directory
9-
zp = Zeropad(I=1)
10-
zp.inputs.in_files = filelist[0]
11-
12-
result = zp.run()
13-
14-
assert (Path(outdir) / "zeropad+tlrc.BRIK").exists()
15-
assert Path(result.outputs.out_file).name == "zeropad+tlrc.BRIK"
16-
17-
18-
def test_zeropad_handles_outfile_specified_nii_gz(create_files_in_directory):
19-
filelist, outdir = create_files_in_directory
20-
zp = Zeropad(I=1, out_file="padded.nii.gz")
21-
zp.inputs.in_files = filelist[0]
22-
23-
result = zp.run()
24-
25-
assert (Path(outdir) / "padded.nii.gz").exists()
26-
assert Path(result.outputs.out_file).name == "padded.nii.gz"
27-
28-
29-
def test_zeropad_keeps_file_after_node_run(create_files_in_directory):
30-
filelist, outdir = create_files_in_directory
31-
32-
zp = Node(
33-
Zeropad(I=1, out_file="padded.nii.gz"), name="test_zeropad", base_dir=outdir
34-
)
35-
zp.inputs.in_files = Path(outdir) / filelist[0]
36-
37-
result = zp.run()
38-
assert (Path(zp.output_dir()) / "padded.nii.gz").exists()
39-
assert Path(result.outputs.out_file).name == "padded.nii.gz"

nipype/interfaces/afni/utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,6 +3391,7 @@ class ZeropadInputSpec(AFNICommandInputSpec):
33913391
copyfile=False,
33923392
)
33933393
out_file = File(
3394+
name_template="zeropad",
33943395
desc="output dataset prefix name (default 'zeropad')",
33953396
argstr="-prefix %s",
33963397
)
@@ -3496,10 +3497,3 @@ class Zeropad(AFNICommand):
34963497
_cmd = "3dZeropad"
34973498
input_spec = ZeropadInputSpec
34983499
output_spec = AFNICommandOutputSpec
3499-
3500-
def _list_outputs(self):
3501-
out_file = getattr(self.inputs, "out_file")
3502-
3503-
if not isdefined(out_file):
3504-
out_file = "zeropad+tlrc.BRIK"
3505-
return {"out_file": op.abspath(out_file)}

nipype/interfaces/utility/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
Requires Packages to be installed
77
"""
88

9-
from .base import IdentityInterface, Rename, Select, Split, Merge, AssertEqual
9+
from .base import IdentityInterface, Rename, Select, Split, Merge, AssertEqual, StringInterpolate
1010
from .csv import CSVReader
1111
from .wrappers import Function

nipype/interfaces/utility/base.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,26 @@ def _run_interface(self, runtime):
430430
if not np.array_equal(data1, data2):
431431
raise RuntimeError("Input images are not exactly equal")
432432
return runtime
433+
434+
435+
class StringInterpolateInputSpec(DynamicTraitedSpec):
436+
input_string = Str(mandatory = True)
437+
438+
class StringInterpolateOutputSpec(TraitedSpec):
439+
output_string = Str()
440+
441+
class StringInterpolate(BaseInterface):
442+
input_spec = StringInterpolateInputSpec
443+
output_spec = StringInterpolateOutputSpec
444+
445+
def _run_interface(self, runtime):
446+
447+
subs = {
448+
k: getattr(self.inputs, k) for k,_ in self.inputs.items() if k != "input_string"
449+
}
450+
self._output_string = self.inputs.input_string.format(**subs)
451+
452+
def _list_outputs(self):
453+
return {
454+
"output_string": self._output_string
455+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from ..base import StringInterpolate
3+
4+
5+
def test_StringInterpolate_inputs():
6+
input_map = dict(
7+
input_string=dict(
8+
mandatory=True,
9+
),
10+
)
11+
inputs = StringInterpolate.input_spec()
12+
13+
for key, metadata in list(input_map.items()):
14+
for metakey, value in list(metadata.items()):
15+
assert getattr(inputs.traits()[key], metakey) == value
16+
17+
18+
def test_StringInterpolate_outputs():
19+
output_map = dict(
20+
output_string=dict(),
21+
)
22+
outputs = StringInterpolate.output_spec()
23+
24+
for key, metadata in list(output_map.items()):
25+
for metakey, value in list(metadata.items()):
26+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/utility/tests/test_base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,16 @@ def test_merge(tmpdir, args, kwargs, in_lists, expected):
7878
assert not isdefined(res.outputs.out)
7979
else:
8080
assert res.outputs.out == expected
81+
82+
83+
def test_string_interpolate():
84+
85+
interpolate = utility.StringInterpolate()
86+
87+
interpolate.inputs.input_string = "{greeting}, {name}!"
88+
interpolate.inputs.greeting = "Hello"
89+
interpolate.inputs.name = "Nipype"
90+
91+
res = interpolate.run()
92+
93+
assert res.outputs.output_string == "Hello, Nipype!"

0 commit comments

Comments
 (0)