mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00:00
加配置合并函数测试,7 例
This commit is contained in:
parent
6eca417534
commit
922adbb290
2 changed files with 45 additions and 0 deletions
0
main/xiaozhi-server/tests/config/__init__.py
Normal file
0
main/xiaozhi-server/tests/config/__init__.py
Normal file
45
main/xiaozhi-server/tests/config/test_config_loader.py
Normal file
45
main/xiaozhi-server/tests/config/test_config_loader.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
"""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
|
||||
Loading…
Reference in a new issue