testsAndMisc/python_pkg/wallpaper_rotator/tests/test_paint.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

67 lines
1.9 KiB
Python

"""Tests for composing the root image and handing it to feh."""
from __future__ import annotations
import subprocess
from typing import TYPE_CHECKING
from PIL import Image
import pytest
from python_pkg.wallpaper_rotator import _paint, _palette
if TYPE_CHECKING:
from pathlib import Path
def test_layout_keeps_only_active_outputs() -> None:
outputs = [
{
"name": "DP-0",
"active": True,
"rect": {"x": 0, "y": 5, "width": 4, "height": 3},
},
{
"name": "HDMI-0",
"active": False,
"rect": {"x": 9, "y": 9, "width": 9, "height": 9},
},
]
assert _paint.layout(outputs) == {"DP-0": (0, 5, 4, 3)}
def test_compose_places_each_image_and_skips_missing_ones() -> None:
rects = {"A": (0, 0, 2, 2), "B": (2, 0, 2, 2), "C": (0, 2, 4, 1)}
images = {
"A": Image.new("RGB", (2, 2), (255, 0, 0)),
"B": Image.new("RGB", (2, 2), (0, 255, 0)),
}
root = _paint.compose(rects, images)
assert root.size == (4, 3)
assert root.getpixel((0, 0)) == (255, 0, 0)
assert root.getpixel((3, 1)) == (0, 255, 0)
assert root.getpixel((0, 2)) == _palette.DEEP
def test_compose_without_outputs_is_one_pixel() -> None:
assert _paint.compose({}, {}).size == (1, 1)
def test_apply_saves_image_and_runs_feh(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
calls: list[list[str]] = []
def fake_run(cmd: list[str], **kwargs: object) -> None:
calls.append(cmd)
assert kwargs == {"check": True}
monkeypatch.setattr(subprocess, "run", fake_run)
target = tmp_path / "cache" / "root.png"
_paint.apply(Image.new("RGB", (3, 2)), target)
with Image.open(target) as saved:
assert saved.size == (3, 2)
assert calls == [
["/usr/bin/feh", "--no-fehbg", "--no-xinerama", "--bg-tile", str(target)]
]