mirror of
https://github.com/RustyRaptor/doge_cogs.git
synced 2026-12-03 15:55:21 -07:00
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
67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
"""``python -m doge_alignment`` on an exported chart."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from alignment_helpers import chart_with
|
|
|
|
from doge_alignment.cli import main
|
|
from doge_alignment.core.storage import to_yaml
|
|
|
|
|
|
@pytest.fixture
|
|
def chart_file(tmp_path: Path) -> Path:
|
|
"""Write a small exported chart."""
|
|
path = tmp_path / "chart.yaml"
|
|
path.write_text(
|
|
to_yaml(chart_with(("1", "Lawful Good"), ("2", "Chaotic Evil")))
|
|
)
|
|
return path
|
|
|
|
|
|
def test_text(chart_file: Path, capsys: pytest.CaptureFixture[str]) -> None:
|
|
"""Text mode prints the chart."""
|
|
assert main(["text", str(chart_file)]) == 0
|
|
assert capsys.readouterr().out.splitlines() == [
|
|
"**Lawful Good**: user1",
|
|
"**Chaotic Evil**: user2",
|
|
]
|
|
|
|
|
|
def test_bad_file_is_a_usage_error(tmp_path: Path) -> None:
|
|
"""Unreadable charts exit with argparse's usage status."""
|
|
bad = tmp_path / "bad.yaml"
|
|
bad.write_text("users: [")
|
|
with pytest.raises(SystemExit) as exit_info:
|
|
main(["text", str(bad)])
|
|
assert exit_info.value.code == 2
|
|
|
|
|
|
def test_image_and_tiles(chart_file: Path, tmp_path: Path) -> None:
|
|
"""Image and tile modes write PNGs (needs ImageMagick)."""
|
|
pytest.importorskip("wand.image", reason="needs ImageMagick")
|
|
out = tmp_path / "chart.png"
|
|
assert (
|
|
main(["image", str(chart_file), "-o", str(out), "--no-avatars"])
|
|
== 0
|
|
)
|
|
assert out.read_bytes().startswith(b"\x89PNG")
|
|
tiles = tmp_path / "tiles"
|
|
assert (
|
|
main(
|
|
[
|
|
"tiles",
|
|
str(chart_file),
|
|
"-o",
|
|
str(tiles),
|
|
"--no-avatars",
|
|
]
|
|
)
|
|
== 0
|
|
)
|
|
assert sorted(p.name for p in tiles.iterdir())[:2] == [
|
|
"1-lg.png",
|
|
"2-ng.png",
|
|
]
|
|
assert len(list(tiles.iterdir())) == 9
|