Spaces:
Sleeping
Sleeping
File size: 1,670 Bytes
f8381b8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | """Verify the new Pydantic ``Settings`` and the legacy ``config.X`` proxy."""
from __future__ import annotations
import config
from config import get_settings, reset_settings, set_settings
def test_defaults() -> None:
s = get_settings()
assert s.debug_mode is False
assert s.debug_level == "full"
assert s.enable_rate_limiting is True
assert s.log_dir is None
assert s.debug_scopes == {"agents": ["all"], "tools": ["all"]}
def test_set_settings_pydantic_names() -> None:
set_settings(debug_mode=True, log_dir="/tmp/x")
s = get_settings()
assert s.debug_mode is True
assert s.log_dir == "/tmp/x"
def test_set_settings_legacy_names() -> None:
set_settings(DEBUG_MODE=True, LOG_DIR="/tmp/y", DEBUG_LEVEL="output")
s = get_settings()
assert s.debug_mode is True
assert s.log_dir == "/tmp/y"
assert s.debug_level == "output"
def test_pep562_legacy_reads() -> None:
"""Existing code that does ``config.DEBUG_MODE`` still works."""
set_settings(debug_mode=True, debug_scopes={"agents": ["CoachAgent"], "tools": ["all"]})
assert config.DEBUG_MODE is True
assert config.DEBUG_SCOPES == {"agents": ["CoachAgent"], "tools": ["all"]}
def test_unknown_attr_raises() -> None:
try:
_ = config.NOT_A_THING # type: ignore[attr-defined]
except AttributeError as e:
assert "NOT_A_THING" in str(e)
else:
raise AssertionError("Expected AttributeError")
def test_reset_settings_round_trip() -> None:
set_settings(debug_mode=True)
assert get_settings().debug_mode is True
reset_settings()
assert get_settings().debug_mode is False # back to default
|