Skip to content

Commit e187d9b

Browse files
committed
Fixed bug in logic when stitching nested dictionaries together
1 parent 716fa93 commit e187d9b

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/murfey/util/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ def _update_nested_values(base: dict[str, Any], new: dict[str, Any]):
174174
if key in base and isinstance(base[key], dict) and isinstance(value, dict):
175175
base[key] = _update_nested_values(base[key], value)
176176
# If new values are lists and a list already exists, extend the list
177-
if key in base and isinstance(base[key], list) and isinstance(value, list):
177+
elif (
178+
key in base and isinstance(base[key], list) and isinstance(value, list)
179+
):
178180
base[key].extend(value)
179181
# Otherwise, overwrite values as normal
180182
else:

tests/util/test_config.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,17 @@ def mock_standard_machine_config_yaml(
171171
for key, value in config.items()
172172
}
173173

174-
# Correct for nested dicts that would have been partially overwritten
175-
machine_config["pkg_1"] = (
176-
{
177-
"file_path": "/path/to/pkg_1/file.txt",
178-
"command": [
179-
"/path/to/executable",
180-
"--some_arg",
181-
"-a",
182-
"./path/to/file",
183-
],
184-
"step_size": 100,
185-
},
186-
)
174+
# Correct nested dicts that would have been partially overwritten
175+
machine_config["pkg_1"] = {
176+
"file_path": "/path/to/pkg_1/file.txt",
177+
"command": [
178+
"/path/to/executable",
179+
"--some_arg",
180+
"-a",
181+
"./path/to/file",
182+
],
183+
"step_size": 100,
184+
}
187185

188186
master_config = {
189187
"m01": machine_config,
@@ -346,3 +344,15 @@ def test_get_machine_config(
346344
config[i].node_creator_queue
347345
== mock_instrument_config["node_creator_queue"]
348346
)
347+
# Extra keys
348+
assert config[i].pkg_1 == {
349+
"file_path": "/path/to/pkg_1/file.txt",
350+
"command": [
351+
"/path/to/executable",
352+
"--some_arg",
353+
"-a",
354+
"./path/to/file",
355+
],
356+
"step_size": 100,
357+
}
358+
assert config[i].pkg_2 == mock_general_config["pkg_2"]

0 commit comments

Comments
 (0)