left4me/l4d2host/tests/test_spec.py
2026-05-05 23:47:06 +02:00

36 lines
996 B
Python

from pathlib import Path
import pytest
from l4d2host.spec import load_spec
def test_minimal_spec_parses(tmp_path: Path) -> None:
path = tmp_path / "server.yaml"
path.write_text("port: 27015\noverlays: [standard]\n")
spec = load_spec(path)
assert spec.port == 27015
assert spec.overlays == ["standard"]
def test_defaults_are_empty_lists(tmp_path: Path) -> None:
path = tmp_path / "server.yaml"
path.write_text("port: 27015\n")
spec = load_spec(path)
assert spec.overlays == []
assert spec.arguments == []
assert spec.config == []
def test_missing_port_fails(tmp_path: Path) -> None:
path = tmp_path / "server.yaml"
path.write_text("overlays: [standard]\n")
with pytest.raises((KeyError, ValueError, TypeError)):
load_spec(path)
def test_unknown_keys_ignored(tmp_path: Path) -> None:
path = tmp_path / "server.yaml"
path.write_text("port: 27015\nfoo: bar\n")
spec = load_spec(path)
assert spec.port == 27015