"""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