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

BUG: actually unset variable if set to None

parent 3a1a890a
No related branches found
No related tags found
No related merge requests found
......@@ -190,11 +190,14 @@ class FileTree(object):
Creates a new FileTree with updated variables
:param variables: new values for the variables
Setting variables to None will force that variable to be empty (useful for non-optional variables)
Setting a variable to None will cause the variable to be unset
:return: New FileTree with same templates for directory names and filenames, but updated variables
"""
new_tree = deepcopy(self)
new_tree.variables.update(variables)
for key, value in variables.items():
if value is None:
del new_tree.variables[key]
return new_tree
def extract_variables(self, short_name: str, filename: str) -> Dict[str, str]:
......
......@@ -77,8 +77,8 @@ def test_custom_tree():
assert len(tree.get_all('sub_file', glob_vars='all')) == 2
assert len(tree.get_all('sub_file')) == 1
assert len(tree.update(opt=None).get_all('sub_file')) == 1
assert len(tree.update(opt=None).get_all('sub_file', glob_vars=['opt'])) == 1
assert len(tree.update(opt=None).get_all('sub_file', glob_vars='all')) == 1
assert len(tree.update(opt=None).get_all('sub_file', glob_vars=['opt'])) == 2
assert len(tree.update(opt=None).get_all('sub_file', glob_vars='all')) == 2
for fn, settings in zip(tree.get_all('sub_file', glob_vars='all'),
tree.get_all_vars('sub_file', glob_vars='all')):
......
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