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

FIX: --slice-time-ref option parsing #2573

Merged
merged 4 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 4 additions & 2 deletions fmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .. import config


def _build_parser():
def _build_parser(**kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a docstring line stating kwargs are intended for argparse.ArgumentParser?

"""Build parser object."""
from functools import partial
from pathlib import Path
Expand Down Expand Up @@ -92,11 +92,13 @@ def _slice_time_ref(value, parser):
config.environment.version
),
formatter_class=ArgumentDefaultsHelpFormatter,
**kwargs,
)
PathExists = partial(_path_exists, parser=parser)
IsFile = partial(_is_file, parser=parser)
PositiveInt = partial(_min_one, parser=parser)
BIDSFilter = partial(_bids_filter, parser=parser)
SliceTimeRef = partial(_slice_time_ref, parser=parser)

# Arguments as specified by BIDS-Apps
# required, positional arguments
Expand Down Expand Up @@ -335,7 +337,7 @@ def _slice_time_ref(value, parser):
required=False,
action="store",
default=None,
type=_slice_time_ref,
type=SliceTimeRef,
help="The time of the reference slice to correct BOLD values to, as a fraction "
"acquisition time. 0 indicates the start, 0.5 the midpoint, and 1 the end "
"of acquisition. The alias `start` corresponds to 0, and `middle` to 0.5. "
Expand Down
17 changes: 17 additions & 0 deletions fmriprep/cli/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ..parser import _build_parser
from .. import version as _version
from ... import config
from ...tests.test_config import _reset_config

MIN_ARGS = ["data/", "out/", "participant"]

Expand Down Expand Up @@ -139,3 +140,19 @@ def test_bids_filter_file(tmp_path, capsys):

err = capsys.readouterr().err
assert "JSON syntax error in:" in err
_reset_config()


@pytest.mark.parametrize("st_ref", (None, "0", "1", "0.5", "start", "middle"))
def test_slice_time_ref(tmp_path, st_ref):
bids_path = tmp_path / "data"
out_path = tmp_path / "out"
args = [str(bids_path), str(out_path), "participant"]
if st_ref:
args.extend(["--slice-time-ref", st_ref])
bids_path.mkdir()

parser = _build_parser()

parser.parse_args(args)
_reset_config()