Wallpaper with fallback hierarchy: config path > Moonarch system default (/usr/share/moonarch/wallpaper.jpg) > package fallback. Applied to both primary and secondary monitors. Default avatar from Moongreet ecosystem with theme-colored SVG rendering via PixbufLoader and proper clipping frame (Gtk.Box with overflow hidden), matching the Moongreet avatar pattern.
54 lines
2.4 KiB
Python
54 lines
2.4 KiB
Python
# ABOUTME: Tests for wallpaper path resolution.
|
|
# ABOUTME: Verifies fallback hierarchy: config > Moonarch system default > package fallback.
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from moonlock.config import Config, resolve_background_path, MOONARCH_WALLPAPER, PACKAGE_WALLPAPER
|
|
|
|
|
|
class TestResolveBackgroundPath:
|
|
"""Tests for the wallpaper fallback hierarchy."""
|
|
|
|
def test_config_path_used_when_file_exists(self, tmp_path: Path):
|
|
"""Config background_path takes priority if the file exists."""
|
|
wallpaper = tmp_path / "custom.jpg"
|
|
wallpaper.write_bytes(b"\xff\xd8")
|
|
config = Config(background_path=str(wallpaper))
|
|
result = resolve_background_path(config)
|
|
assert result == wallpaper
|
|
|
|
def test_config_path_skipped_when_file_missing(self, tmp_path: Path):
|
|
"""Config path should be skipped if the file does not exist."""
|
|
config = Config(background_path="/nonexistent/wallpaper.jpg")
|
|
with patch("moonlock.config.MOONARCH_WALLPAPER", tmp_path / "nope.jpg"):
|
|
result = resolve_background_path(config)
|
|
assert result == PACKAGE_WALLPAPER
|
|
|
|
def test_moonarch_default_used_when_no_config(self, tmp_path: Path):
|
|
"""Moonarch system wallpaper is used when config has no background_path."""
|
|
moonarch_wp = tmp_path / "wallpaper.jpg"
|
|
moonarch_wp.write_bytes(b"\xff\xd8")
|
|
config = Config(background_path=None)
|
|
with patch("moonlock.config.MOONARCH_WALLPAPER", moonarch_wp):
|
|
result = resolve_background_path(config)
|
|
assert result == moonarch_wp
|
|
|
|
def test_moonarch_default_skipped_when_missing(self, tmp_path: Path):
|
|
"""Falls back to package wallpaper when Moonarch default is missing."""
|
|
config = Config(background_path=None)
|
|
with patch("moonlock.config.MOONARCH_WALLPAPER", tmp_path / "nope.jpg"):
|
|
result = resolve_background_path(config)
|
|
assert result == PACKAGE_WALLPAPER
|
|
|
|
def test_package_fallback_always_exists(self):
|
|
"""The package fallback wallpaper must always be present."""
|
|
assert PACKAGE_WALLPAPER.is_file()
|
|
|
|
def test_full_fallback_chain(self, tmp_path: Path):
|
|
"""With no config and no Moonarch default, package fallback is returned."""
|
|
config = Config()
|
|
with patch("moonlock.config.MOONARCH_WALLPAPER", tmp_path / "nope.jpg"):
|
|
result = resolve_background_path(config)
|
|
assert result == PACKAGE_WALLPAPER
|