Skip to content
Snippets Groups Projects
Commit 4e4189de authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

BUG: don't allow variable to span more than one directory or file name

parent edfafa71
No related branches found
No related tags found
No related merge requests found
......@@ -170,6 +170,8 @@ def extract_variables(template, filename, known_vars=None):
raise ValueError('Multiple values found for {}'.format(var))
else:
extracted_value[var] = value
if any('/' in value for value in extracted_value.values()):
continue
for name in find_variables(template):
if name not in extracted_value:
extracted_value[name] = None
......
......@@ -21,3 +21,7 @@ def test_get_variables():
utils.extract_variables('{var}[_{other_var}]_{var}', 'test_foo_bar')
with pytest.raises(ValueError):
utils.extract_variables('bar{var}[_{other_var}]_{var}', 'test')
assert {'subject': '01', 'session': 'A'} == utils.extract_variables('sub-{subject}/[ses-{session}]/T1w.nii.gz', 'sub-01/ses-A/T1w.nii.gz')
with pytest.raises(ValueError):
utils.extract_variables('sub-{subject}/[ses-{session}]/T1w.nii.gz', 'sub-01/other/T1w.nii.gz')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment