testsAndMisc/python_pkg/wallpaper_rotator/tests/test_styles.py
Krzysztof kuhy Rudnicki d502580e3f Dark wallpaper rotator: new style every 3 h
Six text-free styles (gradient, flow/Voronoi, habit heatmap, shutdown
clock, Earth day/night, plasma) replace the white i3 root. A 15-minute
systemd user timer picks a new random style per monitor every 3 hours,
unlike its previous one and the other monitor's; live styles refresh in
between. Also syncs i3/config with the live config and prunes the
oldest evidence artifact for the 60-file cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWX51FMD58yKUC1eYWf
2026-11-11 16:31:06 +01:00

51 lines
1.5 KiB
Python

"""Every style renders the exact output size and stays dark."""
from __future__ import annotations
from datetime import UTC, datetime
from typing import TYPE_CHECKING
import numpy as np
from PIL import Image
import pytest
from python_pkg.wallpaper_rotator._context import RenderContext
from python_pkg.wallpaper_rotator.styles import STYLES
if TYPE_CHECKING:
from pathlib import Path
# Mean brightness ceiling (0-255): the whole point is "not blinding".
_DARK_MEAN = 80
@pytest.fixture
def ctx(tmp_path: Path) -> RenderContext:
earth = tmp_path / "earth"
earth.mkdir()
Image.new("RGB", (64, 32), (40, 90, 160)).save(earth / "day.jpg")
Image.new("RGB", (64, 32), (5, 5, 10)).save(earth / "night.jpg")
conf = tmp_path / "shutdown.conf"
conf.write_text("MON_WED_MINUTES=1380\nTHU_SUN_MINUTES=1380\n")
return RenderContext(
now=datetime(2026, 11, 11, 21, 30, tzinfo=UTC),
data_home=tmp_path / "share",
earth_dir=earth,
shutdown_conf=conf,
)
def test_all_six_styles_registered() -> None:
assert len(STYLES) == 6
@pytest.mark.parametrize("name", sorted(STYLES))
@pytest.mark.parametrize("size", [(384, 216), (256, 144)])
def test_style_is_exact_size_and_dark(
name: str, size: tuple[int, int], ctx: RenderContext
) -> None:
image = STYLES[name].render(ctx, size, np.random.default_rng(3))
assert image.size == size
assert image.mode == "RGB"
assert float(np.asarray(image).mean()) < _DARK_MEAN