Files
silver_pose/v1/tests/test_config.py
T

57 lines
1.6 KiB
Python
Raw Normal View History

2026-07-21 09:45:42 +08:00
import json
import pytest
from v1.config import ConfigError, load_config
def _write_config(path, source):
path.write_text(
json.dumps(
{
"source": source,
"model": {
"path": "models/best.pt",
"sha256": "a" * 64,
"confidence_threshold": 0.25,
},
"event": {
"keypoint_confidence_threshold": 0.4,
"suspect_window_seconds": 0.5,
"confirm_window_seconds": 1.8,
"recovery_window_seconds": 2.0,
"cooldown_seconds": 10.0,
},
"artifacts": {"event_dir": "artifacts/events"},
},
ensure_ascii=False,
),
encoding="utf-8",
)
def test_load_config_resolves_source_from_environment_variable(tmp_path, monkeypatch):
config_file = tmp_path / "config.json"
_write_config(
config_file,
{"id": "lobby-camera-01", "rtsp_url_env": "SILVER_POSE_RTSP_URL"},
)
monkeypatch.setenv("SILVER_POSE_RTSP_URL", "rtsp://demo.invalid/live")
config = load_config(config_file)
assert config.source_id == "lobby-camera-01"
assert config.source_url == "rtsp://demo.invalid/live"
assert config.event.confirm_window_seconds == 1.8
def test_load_config_rejects_embedded_source_address(tmp_path):
config_file = tmp_path / "config.json"
_write_config(
config_file,
{"id": "lobby-camera-01", "url": "rtsp://demo.invalid/live"},
)
with pytest.raises(ConfigError, match="rtsp_url_env"):
load_config(config_file)