Skip to content

Commit cedf5bc

Browse files
committed
Fix and test.
1 parent 7bbb074 commit cedf5bc

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

fmriprep/cli/parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __call__(self, parser, namespace, values, option_string=None):
6363
delattr(namespace, self.dest)
6464

6565
class ToDict(Action):
66+
def __call__(self, parser, namespace, values, option_string=None):
6667
d = {}
6768
for spec in values:
6869
try:
@@ -73,8 +74,9 @@ class ToDict(Action):
7374
name = loc.name
7475

7576
if name in d:
76-
raise ValueError(f"Received duplicate derivative name: {name}")
77-
d[k] = Path(v)
77+
raise ValueError(f'Received duplicate derivative name: {name}')
78+
79+
d[name] = loc
7880
setattr(namespace, self.dest, d)
7981

8082
def _path_exists(path, parser):

fmriprep/cli/tests/test_parser.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,25 @@ def test_derivatives(tmp_path):
248248
# Providing --derivatives without names should automatically label them
249249
temp_args = args + ['--derivatives', str(bids_path / 'derivatives/smriprep')]
250250
opts = parser.parse_args(temp_args)
251-
assert opts.derivatives == {'deriv-0': str(bids_path / 'derivatives/smriprep')}
251+
assert opts.derivatives == {'smriprep': bids_path / 'derivatives/smriprep'}
252252
_reset_config()
253253

254254
# Providing --derivatives with names should use them
255255
temp_args = args + [
256256
'--derivatives',
257-
f'smriprep={str(bids_path / "derivatives/smriprep")}',
257+
f'anat={str(bids_path / "derivatives/smriprep")}',
258258
]
259259
opts = parser.parse_args(temp_args)
260-
assert opts.derivatives == {'smriprep': str(bids_path / 'derivatives/smriprep')}
260+
assert opts.derivatives == {'anat': bids_path / 'derivatives/smriprep'}
261+
_reset_config()
262+
263+
# Providing multiple unlabeled derivatives with the same name should raise an error
264+
temp_args = args + [
265+
'--derivatives',
266+
str(bids_path / 'derivatives_01/smriprep'),
267+
str(bids_path / 'derivatives_02/smriprep'),
268+
]
269+
with pytest.raises(ValueError, match='Received duplicate derivative name'):
270+
parser.parse_args(temp_args)
271+
261272
_reset_config()

0 commit comments

Comments
 (0)