-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protocols: fix mutation of overrides (#650)
Currently the `overrides` input dictionary provided to the `get_builder_from_protocol` method can be mutated to also include the defaults from the protocol. Here we make a copy of the `right` dictionary in the `recursive_merge` function, to prevent the key/value pairs of the `left` dictionary to be added to the `right` one. This prevents the mutation of the `overrides` argument.
- Loading branch information
Showing
2 changed files
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for the utility functions for the protocols.""" | ||
|
||
|
||
def test_recursive_merge(): | ||
"""Test the recursive merge function.""" | ||
from aiida_quantumespresso.workflows.protocols.utils import recursive_merge | ||
|
||
left_dict = {'a': {'b': 1, 'c': {'d': 2}}, 'g': 3} | ||
right_dict = {'a': {'c': {'d': 'D'}}, 'e': {'f': 'F'}} | ||
merged = recursive_merge(left_dict, right_dict) | ||
|
||
assert right_dict == {'a': {'c': {'d': 'D'}}, 'e': {'f': 'F'}} | ||
|
||
assert merged == {'a': {'b': 1, 'c': {'d': 'D'}}, 'e': {'f': 'F'}, 'g': 3} |