Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] FIX - AFNI Zeropad sets out_file #3641

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion nipype/interfaces/afni/tests/test_auto_Zeropad.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def test_Zeropad_inputs():
out_file=dict(
argstr="-prefix %s",
extensions=None,
name_template="zeropad",
),
outputtype=dict(),
z=dict(
Expand Down
39 changes: 39 additions & 0 deletions nipype/interfaces/afni/tests/test_extra_Zeropad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from pathlib import Path
from nipype import Node
from nipype.interfaces.afni import Zeropad
from nipype.testing.fixtures import create_files_in_directory


def test_zeropad_handles_outfile_default(create_files_in_directory):
filelist, outdir = create_files_in_directory
zp = Zeropad(I=1)
zp.inputs.in_files = filelist[0]

result = zp.run()

assert (Path(outdir) / "zeropad+tlrc.BRIK").exists()
assert Path(result.outputs.out_file).name == "zeropad+tlrc.BRIK"

Check warning on line 15 in nipype/interfaces/afni/tests/test_extra_Zeropad.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/afni/tests/test_extra_Zeropad.py#L14-L15

Added lines #L14 - L15 were not covered by tests


def test_zeropad_handles_outfile_specified_nii_gz(create_files_in_directory):
filelist, outdir = create_files_in_directory
zp = Zeropad(I=1, out_file="padded.nii.gz")
zp.inputs.in_files = filelist[0]

result = zp.run()

assert (Path(outdir) / "padded.nii.gz").exists()
assert Path(result.outputs.out_file).name == "padded.nii.gz"

Check warning on line 26 in nipype/interfaces/afni/tests/test_extra_Zeropad.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/afni/tests/test_extra_Zeropad.py#L25-L26

Added lines #L25 - L26 were not covered by tests


def test_zeropad_keeps_file_after_node_run(create_files_in_directory):
Comment on lines +1 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from pathlib import Path
from nipype import Node
from nipype.interfaces.afni import Zeropad
from nipype.testing.fixtures import create_files_in_directory
def test_zeropad_handles_outfile_default(create_files_in_directory):
filelist, outdir = create_files_in_directory
zp = Zeropad(I=1)
zp.inputs.in_files = filelist[0]
result = zp.run()
assert (Path(outdir) / "zeropad+tlrc.BRIK").exists()
assert Path(result.outputs.out_file).name == "zeropad+tlrc.BRIK"
def test_zeropad_handles_outfile_specified_nii_gz(create_files_in_directory):
filelist, outdir = create_files_in_directory
zp = Zeropad(I=1, out_file="padded.nii.gz")
zp.inputs.in_files = filelist[0]
result = zp.run()
assert (Path(outdir) / "padded.nii.gz").exists()
assert Path(result.outputs.out_file).name == "padded.nii.gz"
def test_zeropad_keeps_file_after_node_run(create_files_in_directory):
from pathlib import Path
from shutil import which
import pytest
from nipype import Node
from nipype.interfaces.afni import Zeropad
from nipype.testing.fixtures import create_files_in_directory
needs_3dZeropad = pytest.mark.skipif(
not which('3dZeropad'),
reason='Needs AFNI 3dZeropad installed'
)
@needs_3dZeropad
def test_zeropad_handles_outfile_default(create_files_in_directory):
filelist, outdir = create_files_in_directory
zp = Zeropad(I=1)
zp.inputs.in_files = filelist[0]
result = zp.run()
assert (Path(outdir) / "zeropad+tlrc.BRIK").exists()
assert Path(result.outputs.out_file).name == "zeropad+tlrc.BRIK"
@needs_3dZeropad
def test_zeropad_handles_outfile_specified_nii_gz(create_files_in_directory):
filelist, outdir = create_files_in_directory
zp = Zeropad(I=1, out_file="padded.nii.gz")
zp.inputs.in_files = filelist[0]
result = zp.run()
assert (Path(outdir) / "padded.nii.gz").exists()
assert Path(result.outputs.out_file).name == "padded.nii.gz"
@needs_3dZeropad
def test_zeropad_keeps_file_after_node_run(create_files_in_directory):

filelist, outdir = create_files_in_directory

zp = Node(
Zeropad(I=1, out_file="padded.nii.gz"), name="test_zeropad", base_dir=outdir
)
zp.inputs.in_files = Path(outdir) / filelist[0]

result = zp.run()
assert (Path(zp.output_dir()) / "padded.nii.gz").exists()
assert Path(result.outputs.out_file).name == "padded.nii.gz"

Check warning on line 39 in nipype/interfaces/afni/tests/test_extra_Zeropad.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/afni/tests/test_extra_Zeropad.py#L38-L39

Added lines #L38 - L39 were not covered by tests
8 changes: 7 additions & 1 deletion nipype/interfaces/afni/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3391,7 +3391,6 @@
copyfile=False,
)
out_file = File(
name_template="zeropad",
desc="output dataset prefix name (default 'zeropad')",
argstr="-prefix %s",
)
Expand Down Expand Up @@ -3497,3 +3496,10 @@
_cmd = "3dZeropad"
input_spec = ZeropadInputSpec
output_spec = AFNICommandOutputSpec

def _list_outputs(self):
out_file = getattr(self.inputs, "out_file")

Check warning on line 3501 in nipype/interfaces/afni/utils.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/afni/utils.py#L3501

Added line #L3501 was not covered by tests

if not isdefined(out_file):
out_file = "zeropad+tlrc.BRIK"
return {"out_file": op.abspath(out_file)}

Check warning on line 3505 in nipype/interfaces/afni/utils.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/afni/utils.py#L3504-L3505

Added lines #L3504 - L3505 were not covered by tests
Loading