xiaozhi-esp32-server/main/xiaozhi-server/tests/config/test_config_loader.py
2026-09-02 22:24:35 +08:00

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