mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-24 04:19:48 +01:00
45 lines
No EOL
1.3 KiB
Python
45 lines
No EOL
1.3 KiB
Python
"""Tests for the recursive config merge in config/config_loader.py."""
|
|
from config.config_loader import merge_configs
|
|
|
|
|
|
def test_merge_simple_override():
|
|
default = {"a": 1, "b": 2}
|
|
custom = {"b": 99}
|
|
assert merge_configs(default, custom) == {"a": 1, "b": 99}
|
|
|
|
|
|
def test_merge_adds_new_key():
|
|
default = {"a": 1}
|
|
custom = {"b": 2}
|
|
assert merge_configs(default, custom) == {"a": 1, "b": 2}
|
|
|
|
|
|
def test_merge_recursive_dict():
|
|
default = {"x": {"a": 1, "b": 2}}
|
|
custom = {"x": {"b": 99}}
|
|
assert merge_configs(default, custom) == {"x": {"a": 1, "b": 99}}
|
|
|
|
|
|
def test_merge_deep_recursive():
|
|
default = {"a": {"b": {"c": 1, "d": 2}}}
|
|
custom = {"a": {"b": {"c": 99}}}
|
|
assert merge_configs(default, custom) == {"a": {"b": {"c": 99, "d": 2}}}
|
|
|
|
|
|
def test_merge_replaces_non_dict_with_dict():
|
|
default = {"a": 1}
|
|
custom = {"a": {"nested": True}}
|
|
assert merge_configs(default, custom) == {"a": {"nested": True}}
|
|
|
|
|
|
def test_merge_replaces_dict_with_non_dict():
|
|
default = {"a": {"nested": True}}
|
|
custom = {"a": 1}
|
|
assert merge_configs(default, custom) == {"a": 1}
|
|
|
|
|
|
def test_merge_does_not_mutate_defaults():
|
|
default = {"a": {"b": 1}}
|
|
custom = {"a": {"c": 2}}
|
|
merge_configs(default, custom)
|
|
assert default == {"a": {"b": 1}} # unchanged |