Die Regex VALID_THEME_NAME blockierte Theme-Namen mit '+' (z.B. catppuccin-mocha-lavender-standard+default). Da GTK den Theme-Namen intern über Standardverzeichnisse auflöst, ist eigene Validierung unnötig und kontraproduktiv.
111 lines
3.4 KiB
Python
111 lines
3.4 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, resolve_wallpaper_path, 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_loads_gtk_theme(self, tmp_path: Path) -> None:
|
|
toml_file = tmp_path / "moongreet.toml"
|
|
toml_file.write_text(
|
|
"[appearance]\n"
|
|
'gtk-theme = "Catppuccin-Mocha-Standard-Blue-Dark"\n'
|
|
)
|
|
|
|
config = load_config(toml_file)
|
|
|
|
assert config.gtk_theme == "Catppuccin-Mocha-Standard-Blue-Dark"
|
|
|
|
def test_returns_none_gtk_theme_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.gtk_theme 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"
|
|
|
|
|
|
class TestResolveWallpaperPath:
|
|
"""Tests for resolving the wallpaper path from config or package default."""
|
|
|
|
def test_uses_configured_path_when_exists(self, tmp_path: Path) -> None:
|
|
wallpaper = tmp_path / "custom.jpg"
|
|
wallpaper.write_bytes(b"fake-image")
|
|
config = Config(background=wallpaper)
|
|
|
|
path, ctx = resolve_wallpaper_path(config)
|
|
|
|
assert path == wallpaper
|
|
assert ctx is None
|
|
|
|
def test_falls_back_to_package_default(self) -> None:
|
|
config = Config(background=None)
|
|
|
|
path, ctx = resolve_wallpaper_path(config)
|
|
|
|
assert path is not None
|
|
assert path.exists()
|
|
assert ctx is not None
|
|
# Clean up context manager
|
|
ctx.__exit__(None, None, None)
|
|
|
|
def test_falls_back_when_configured_path_missing(self, tmp_path: Path) -> None:
|
|
config = Config(background=tmp_path / "nonexistent.jpg")
|
|
|
|
path, ctx = resolve_wallpaper_path(config)
|
|
|
|
assert path is not None
|
|
assert path.exists()
|
|
assert ctx is not None
|
|
ctx.__exit__(None, None, None)
|