Files
doge_cogs/tests/test_alignment_render.py
T
ziadarafatandClaude Opus 5.5 ee17b3c3e5 Bring doge_alignment up to the watch cog's standards
Fixes:
- setting or removing an alignment dropped the server's admin list
- charts were YAML files inside the cog folder, which Downloader replaces
  on every update; they now live in Red's Config
- the cog imported Wand (ImageMagick) at load time and couldn't load
  where ImageMagick is missing, such as dogebot's container
- info.json pip-installed this whole repo, red-discordbot and discord
  included, into Red's lib folder
- /alignment_remove_admin let the bot owner past one check and then
  refused them at the next

Structure: the cog folder is self-contained like watch. chart.py holds
the rules as pure functions; render.py keeps the image helpers (grid
layout fixed, debug viewers removed) and is imported only when used. The
repo is now a uv virtual project (no package build), with Red pinned to
dogebot's 3.5.24.

Standards: ruff with the lptn settings, ty and annotations, and pytest
(chart rules, Config storage and red_delete_data_for_user on Red's test
backend, image helpers) now cover both cogs; 52 tests. Missing features
are listed in doge_alignment/TODO.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GUebqhE8dK19vyn4Ct5g1L
2026-11-05 09:49:10 -07:00

42 lines
1.4 KiB
Python

"""The image helpers for the (future) chart picture."""
from typing import get_args
import pytest
pytest.importorskip("wand.image", reason="needs ImageMagick")
from doge_alignment.render import ( # noqa: E402
BorderShape,
grid_positions,
process_avatar,
solid_color_background,
)
def test_grid_positions_fill_rows_of_three() -> None:
"""Cells go left to right, then down, with gaps between them."""
assert grid_positions(4, (100, 50), gap=10) == [
(0, 0),
(110, 0),
(220, 0),
(0, 60),
]
@pytest.mark.parametrize("shape", get_args(BorderShape))
def test_process_avatar_size_and_border(shape: BorderShape) -> None:
"""Avatars are resized, shaped and bordered on a copy."""
with solid_color_background(300, 200, "blue") as original:
out = process_avatar(original, (64, 64), 4, "green", shape)
assert out.size == (72, 72)
assert original.size == (300, 200)
def test_circle_has_transparent_corners() -> None:
"""Outside the circle is see-through, inside is not."""
with solid_color_background(64, 64, "red") as img:
out = process_avatar(img, (64, 64), 0, "black", "circle")
assert out[0, 0].alpha == 0
assert out[32, 32].alpha == 1