Files
automaton/tests/test_config.py
T

56 lines
1.8 KiB
Python
Raw Normal View History

"""Tests for automaton.dashboard.config."""
import json
from pathlib import Path
import pytest
from automaton.dashboard.config import DashboardConfig, get_config_path
def test_config_defaults() -> None:
config = DashboardConfig()
assert config.auto_refresh_interval == 2
assert config.default_view == "board"
assert config.column_width == 30
assert config.show_timelines is True
assert config.theme == "default"
def test_config_validation() -> None:
config = DashboardConfig(auto_refresh_interval=0, default_view="invalid", column_width=5, theme="neon")
errors = config.validate()
assert any("auto_refresh_interval" in e for e in errors)
assert any("default_view" in e for e in errors)
assert any("column_width" in e for e in errors)
assert any("theme" in e for e in errors)
def test_config_from_dict() -> None:
config = DashboardConfig.from_dict({"theme": "dark", "column_width": 50})
assert config.theme == "dark"
assert config.column_width == 50
assert config.default_view == "board" # default preserved
def test_config_from_file(tmp_path: Path) -> None:
config_path = tmp_path / "dashboard-config.json"
config_path.write_text(json.dumps({"theme": "light", "auto_refresh_interval": 5}))
config = DashboardConfig.from_file(config_path)
assert config.theme == "light"
assert config.auto_refresh_interval == 5
def test_config_save(tmp_path: Path) -> None:
config_path = tmp_path / "subdir" / "dashboard-config.json"
config = DashboardConfig(theme="dark")
config.save(config_path)
assert config_path.exists()
data = json.loads(config_path.read_text())
assert data["theme"] == "dark"
def test_get_config_path(tmp_path: Path) -> None:
path = get_config_path(tmp_path)
assert path == tmp_path / ".automaton" / "dashboard-config.json"