Files
doge_cogs/tests/test_alignment_view.py
T
Ziad ArafatandClaude Opus 5.5 b575ab6f75 doge_alignment: chart pictures, one command group, Discord-free core
Draw the chart with ImageMagick: one 3x3 picture, or nine tiles sent as a
Components V2 media gallery (3x3), with avatars cut into circles. Names and
avatars are looked up live; people who left are greyed out.

Move all logic into doge_alignment/core, which imports neither discord.py
nor Red: immutable Chart dataclasses with pure operations, Config/YAML
storage, a view model, pure layout geometry, a Wand painter and an avatar
fetcher. The cog and a new CLI (python -m doge_alignment) are front ends.

Commands are now one hybrid `alignment` group (text and slash): show, set,
remove, prune, clear, style, export, import, admin add/remove/list. Red's
admin/mod roles, Administrators and the server owner count as admins.

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

71 lines
2.6 KiB
Python

"""What gets shown: cells, live names, people who left, text."""
from alignment_helpers import chart_with
from doge_alignment.core.alignments import ALIGNMENTS
from doge_alignment.core.chart import Entry, place
from doge_alignment.core.view import (
Profile,
absent,
cells,
everyone,
format_text,
tile_filename,
)
def test_nine_cells_in_order_even_when_empty() -> None:
"""Every alignment gets a cell, in chart order."""
result = cells(chart_with(("1", "Chaotic Evil")))
assert tuple(c.alignment for c in result) == ALIGNMENTS
assert [len(c.people) for c in result] == [0] * 8 + [1]
def test_live_profiles_win_and_absent_people_are_marked() -> None:
"""Live names replace saved ones; unknown people have left."""
chart = place(
chart_with(("1", "Lawful Good")),
"2",
Entry("Lawful Good", "old name", "https://x/old.png"),
)
live = {"1": Profile("Alice", "https://x/a.png")}
(good, *_) = cells(chart, live.get)
assert [(p.name, p.present) for p in good.people] == [
("Alice", True),
("old name", False),
]
assert good.people[1].avatar_url == "https://x/old.png"
assert absent(chart, live.get) == ("2",)
def test_without_lookup_everyone_is_present() -> None:
"""Charts from files have nobody to look up."""
result = cells(chart_with(("1", "True Neutral")))
assert all(p.present for p in everyone(result))
def test_people_sorted_by_name_case_insensitively() -> None:
"""Within a cell, present people come first, then by name."""
chart = chart_with(("1", "True Neutral"), ("2", "True Neutral"))
chart = place(chart, "3", Entry("True Neutral", "Bob"))
names = {"1": Profile("carol"), "3": Profile("Bob")}
middle = cells(chart, names.get)[4]
assert [p.name for p in middle.people] == ["Bob", "carol", "user2"]
def test_format_text_skips_empty_cells_and_marks_leavers() -> None:
"""Text lists only cells with people, in chart order."""
chart = chart_with(("1", "Chaotic Evil"), ("2", "Lawful Good"))
text = format_text(cells(chart, {"1": Profile("Eve")}.get))
assert text.splitlines() == [
"**Lawful Good**: ~~user2~~ (left)",
"**Chaotic Evil**: Eve",
]
def test_tile_filenames() -> None:
"""Tiles are numbered in chart order with the abbreviation."""
result = cells(chart_with())
assert tile_filename(1, result[0]) == "1-lg.png"
assert tile_filename(9, result[8]) == "9-ce.png"