testsAndMisc/python_pkg/app_icons/tests/test_registry.py
Krzysztof kuhy Rudnicki 6383bd7452
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
app_icons: tunedeck gets headphones; later entries move to _apps_more
apps.py was one entry short of the 250-line cap, so tutor and the new
tunedeck entry live in _apps_more.MORE_APPS, merged into APPS unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CyiH5e86uaQzhXzVXTQiVc
2026-10-16 16:16:09 +02:00

109 lines
4.0 KiB
Python

"""Tests for the app registry, glyph library and family style invariants."""
from __future__ import annotations
import pytest
from python_pkg.app_icons import apps, glyphs, style
class TestGlyphLookup:
def test_known_glyph(self) -> None:
assert glyphs.get_glyph("barbell").name == "barbell"
def test_unknown_glyph_lists_alternatives(self) -> None:
with pytest.raises(KeyError, match="barbell"):
glyphs.get_glyph("nope")
class TestAppLookup:
def test_known_app(self) -> None:
assert apps.get_app("todo").glyph == "checklist"
def test_unknown_app_lists_alternatives(self) -> None:
with pytest.raises(KeyError, match="todo"):
apps.get_app("nope")
def test_asset_dir_is_under_repo(self) -> None:
app = apps.get_app("todo")
assert app.asset_dir == app.repo / "assets" / "icon"
class TestFamilyInvariants:
def test_every_app_references_a_real_glyph(self) -> None:
for app in apps.APPS.values():
assert app.glyph in glyphs.GLYPHS
def test_accents_are_shared(self) -> None:
"""Every app uses the one family accent; apps differ by glyph only."""
accents = {app.accent for app in apps.APPS.values()}
assert accents == {"#B8862E"}
def test_accents_are_hex_triplets(self) -> None:
for app in apps.APPS.values():
assert app.accent.startswith("#")
assert len(app.accent) == 7
int(app.accent[1:], 16)
def test_no_glyph_is_reused(self) -> None:
"""Apps are told apart by glyph; a new app must not borrow one."""
shared_by_design = {"track-bars"} # kuhylog + betting_sim, pre-existing
used = [app.glyph for app in apps.APPS.values()]
reused = {glyph for glyph in used if used.count(glyph) > 1}
assert reused <= shared_by_design
def test_safe_box_fits_inside_canvas(self) -> None:
assert style.SAFE_BOX < style.CANVAS
assert style.MIN_NEGATIVE_SPACE == style.STROKE_WIDTH / 2
def test_no_glyph_paints_the_background_colour(self) -> None:
"""A hole must be cut, not painted.
``icon_foreground`` and ``icon_monochrome`` are rendered on
transparency, so a shape filled with ``style.BACKGROUND`` to fake a
hole shows up as a charcoal blob on those layers instead of
disappearing — and on the monochrome layer, which the system
recolours, in the wrong colour entirely. Holes belong in the path as
``fill-rule="evenodd"`` subpaths.
"""
for glyph in glyphs.GLYPHS.values():
assert style.BACKGROUND.lower() not in glyph.body.lower(), (
f"{glyph.name} paints style.BACKGROUND; cut the hole with "
f'fill-rule="evenodd" instead'
)
class TestHourglassGlyph:
def test_daily_limits_uses_it(self) -> None:
assert apps.get_app("daily_limits").glyph == "hourglass"
def test_sand_is_filled_in_the_accent(self) -> None:
"""The sand takes the accent marker, so the monochrome layer recolours it."""
body = glyphs.get_glyph("hourglass").body
assert f'fill="{style.ACCENT_MARKER}"' in body
assert 'stroke="none"' in body
class TestLightbulbGlyph:
def test_tutor_uses_it(self) -> None:
app = apps.get_app("tutor")
assert app.glyph == "lightbulb"
assert app.web_dir == app.repo / "web"
def test_bulb_is_filled_in_the_accent(self) -> None:
"""The bulb takes the accent marker, so the monochrome layer recolours it."""
assert f'fill="{style.ACCENT_MARKER}"' in glyphs.get_glyph("lightbulb").body
class TestHeadphonesGlyph:
def test_tunedeck_uses_it(self) -> None:
app = apps.get_app("tunedeck")
assert app.glyph == "headphones"
assert app.linux
def test_cups_are_filled_in_the_accent(self) -> None:
"""The cups take the accent marker, so the monochrome layer recolours it."""
body = glyphs.get_glyph("headphones").body
assert f'fill="{style.ACCENT_MARKER}"' in body
assert 'stroke="none"' in body