testsAndMisc/python_pkg/app_icons/tests/test_registry_code_apps.py
Krzysztof kuhy Rudnicki e43500a950
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Register kartka, leetcode, todoimpl icons
Port the three shipped family glyphs verbatim so the generator can
regenerate them unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 14:42:54 +01:00

71 lines
2.7 KiB
Python

"""Tests for the kartka, leetcode and todoimpl registry entries.
Those three apps shipped family icons before they were registered here; the
glyphs are ports of the shipped ``icon_foreground.svg`` fragments, so these
tests render each one through the real pipeline into ``tmp_path`` (never the
app's own repo) and check the standard-size set comes out.
"""
from __future__ import annotations
import dataclasses
from typing import TYPE_CHECKING
from PIL import Image
import pytest
from python_pkg.app_icons import apps, generate, glyphs, labels, style
if TYPE_CHECKING:
from pathlib import Path
# key -> (glyph, icon_name, linux, repo path under ~)
_EXPECTED: dict[str, tuple[str, str, bool, str]] = {
"kartka": ("document-split", "kartka", True, "src/kartka"),
"leetcode": ("code-brackets", "leetcode-guard-app", True, "src/leetcode-guard/app"),
"todoimpl": ("screen-tick-play", "todoimpl", False, "src/todoImplementer/app"),
}
@pytest.mark.parametrize("key", sorted(_EXPECTED))
class TestCodeAppEntries:
def test_entry_matches_disk_facts(self, key: str) -> None:
glyph, icon_name, linux, repo = _EXPECTED[key]
app = apps.get_app(key)
assert app.glyph == glyph
assert app.icon_name == icon_name
assert app.linux is linux
assert app.repo == apps.Path.home() / repo
assert glyphs.get_glyph(glyph).name == glyph
def test_label_is_valid(self, key: str) -> None:
assert labels.label_problems(apps.get_app(key).label) == []
def test_renders_standard_size_set(self, key: str, tmp_path: Path) -> None:
app = dataclasses.replace(apps.get_app(key), repo=tmp_path / key)
written = generate.write_assets(app)
assert sorted(path.name for path in written) == sorted(
f"{stem}.{ext}"
for stem in ("icon", "icon_foreground", "icon_monochrome")
for ext in ("svg", "png")
)
for path in written:
if path.suffix == ".png":
with Image.open(path) as image:
assert image.size == (style.CANVAS, style.CANVAS)
@pytest.mark.parametrize("key", ["kartka", "leetcode"])
def test_renders_linux_set(key: str, tmp_path: Path) -> None:
icons = generate.write_linux_icons(apps.get_app(key), tmp_path)
assert len(icons) == len(style.LINUX_ICON_SIZES)
for size, path in zip(style.LINUX_ICON_SIZES, icons, strict=True):
with Image.open(path) as image:
assert image.size == (size, size)
def test_filled_parts_take_the_accent_marker() -> None:
"""Folded corner and play triangle recolour on the monochrome layer."""
for name in ("document-split", "screen-tick-play"):
assert f'fill="{style.ACCENT_MARKER}"' in glyphs.get_glyph(name).body