Skip to content

Commit

Permalink
Fix and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Mar 29, 2024
1 parent 7bbb074 commit cedf5bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions fmriprep/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __call__(self, parser, namespace, values, option_string=None):
delattr(namespace, self.dest)

class ToDict(Action):
def __call__(self, parser, namespace, values, option_string=None):
d = {}
for spec in values:
try:
Expand All @@ -73,8 +74,9 @@ class ToDict(Action):
name = loc.name

if name in d:
raise ValueError(f"Received duplicate derivative name: {name}")
d[k] = Path(v)
raise ValueError(f'Received duplicate derivative name: {name}')

d[name] = loc
setattr(namespace, self.dest, d)

def _path_exists(path, parser):
Expand Down
17 changes: 14 additions & 3 deletions fmriprep/cli/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,25 @@ def test_derivatives(tmp_path):
# Providing --derivatives without names should automatically label them
temp_args = args + ['--derivatives', str(bids_path / 'derivatives/smriprep')]
opts = parser.parse_args(temp_args)
assert opts.derivatives == {'deriv-0': str(bids_path / 'derivatives/smriprep')}
assert opts.derivatives == {'smriprep': bids_path / 'derivatives/smriprep'}
_reset_config()

# Providing --derivatives with names should use them
temp_args = args + [
'--derivatives',
f'smriprep={str(bids_path / "derivatives/smriprep")}',
f'anat={str(bids_path / "derivatives/smriprep")}',
]
opts = parser.parse_args(temp_args)
assert opts.derivatives == {'smriprep': str(bids_path / 'derivatives/smriprep')}
assert opts.derivatives == {'anat': bids_path / 'derivatives/smriprep'}
_reset_config()

# Providing multiple unlabeled derivatives with the same name should raise an error
temp_args = args + [
'--derivatives',
str(bids_path / 'derivatives_01/smriprep'),
str(bids_path / 'derivatives_02/smriprep'),
]
with pytest.raises(ValueError, match='Received duplicate derivative name'):
parser.parse_args(temp_args)

_reset_config()

0 comments on commit cedf5bc

Please sign in to comment.