Files
pyMCPBroker/tests/test_config.py
2026-04-13 23:42:02 +02:00

24 lines
900 B
Python

from __future__ import annotations
import json
from pathlib import Path
import pytest
from pyMCPBroker.config import load_config
def test_env_substitution(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("BROKER_CMD", "python fake.py")
path = tmp_path / "config.json"
path.write_text(json.dumps({"backends": {"x": {"backend": "stdio", "command": "${BROKER_CMD}"}}, "tree": {"path": "/", "type": "node", "children": []}}), encoding="utf-8")
cfg = load_config(path)
assert cfg.backends["x"].command == "python fake.py"
def test_env_missing_raises(tmp_path: Path) -> None:
path = tmp_path / "config.json"
path.write_text(json.dumps({"backends": {"x": {"backend": "stdio", "command": "${MISSING_VAR}"}}, "tree": {"path": "/", "type": "node", "children": []}}), encoding="utf-8")
with pytest.raises(ValueError):
load_config(path)