加配置合并函数测试,7 例

This commit is contained in:
hrz 2026-09-02 19:59:08 +08:00
parent 6eca417534
commit 922adbb290
2 changed files with 45 additions and 0 deletions

View 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