greetd-moongreet/tests/test_config.py
nevaforget 4cd73a430b fix: Audit-Findings — Realize-Handler, Thread-Safety, Input-Validierung
- _on_realize implementiert (war nur connected, nicht definiert)
- do_unrealize für as_file() Context-Manager-Cleanup
- threading.Lock für _greetd_sock Race Condition
- TOML-Parsing-Fehler abfangen statt Crash
- last-user Datei: Längen- und Zeichenvalidierung
- detect_locale: non-alpha LANG-Werte abweisen
- exec_cmd Plausibility-Check mit shutil.which
- Exception-Details ins Log statt in die UI
- subprocess.run Timeout für Power-Actions
- Sequence[Path] statt tuple[Path, ...] in get_sessions
- Mock-Server _recvall für fragmentierte Reads
- [behavior]-Config-Sektion entfernt (unimplementiert)
- Design Decisions in CLAUDE.md dokumentiert
2026-03-26 12:56:52 +01:00

56 lines
1.7 KiB
Python

# ABOUTME: Tests for configuration loading from moongreet.toml.
# ABOUTME: Verifies parsing of appearance and behavior settings.
from pathlib import Path
import pytest
from moongreet.config import load_config, Config
class TestLoadConfig:
"""Tests for loading moongreet.toml configuration."""
def test_loads_background_path(self, tmp_path: Path) -> None:
toml_file = tmp_path / "moongreet.toml"
toml_file.write_text(
"[appearance]\n"
'background = "/usr/share/backgrounds/test.jpg"\n'
)
config = load_config(toml_file)
assert config.background == Path("/usr/share/backgrounds/test.jpg")
def test_returns_none_background_when_missing(self, tmp_path: Path) -> None:
toml_file = tmp_path / "moongreet.toml"
toml_file.write_text("[appearance]\n")
config = load_config(toml_file)
assert config.background is None
def test_returns_defaults_for_missing_file(self, tmp_path: Path) -> None:
config = load_config(tmp_path / "nonexistent.toml")
assert config.background is None
def test_returns_defaults_for_corrupt_toml(self, tmp_path: Path) -> None:
toml_file = tmp_path / "moongreet.toml"
toml_file.write_text("this is not valid [[[ toml !!!")
config = load_config(toml_file)
assert config.background is None
def test_resolves_relative_path_against_config_dir(self, tmp_path: Path) -> None:
toml_file = tmp_path / "moongreet.toml"
toml_file.write_text(
"[appearance]\n"
'background = "wallpaper.jpg"\n'
)
config = load_config(toml_file)
assert config.background == tmp_path / "wallpaper.jpg"