testsAndMisc/python_pkg/app_icons/tests/test_cli.py
Krzysztof kuhy Rudnicki 27f44cad4b Add shared launcher-icon generator for the Flutter apps
Every Flutter app still shipped the stock Flutter "beach" launcher icon, and
none had an adaptive-icon descriptor at all. Rather than hand-drawing five
one-off icons, define the family once and let each app contribute only an
accent colour and a glyph.

The family: a charcoal #1B1D21 field carrying one glyph in that app's own
theme seed colour, at a single stroke weight. Glyphs are optically centred
automatically - render.centre_offset rasterises a glyph alone, measures its
ink box, and translates (never scales) the fragment, so a row of icons lines
up while every icon keeps the exact family stroke weight.

safe_box_overflow warns when a glyph exceeds the 560px adaptive-icon safe
box; it caught three real overflows that a launcher mask would have clipped.

The registry points dufs_client at ~/dufs-cloud/app: ~/dufs_client was a
stale, remote-less checkout with an identical package name, since deleted.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 16:55:48 +02:00

108 lines
3.4 KiB
Python

"""Tests for app_icons.cli."""
from __future__ import annotations
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
from python_pkg.app_icons import apps, cli
MOD = "python_pkg.app_icons.cli"
class TestSelected:
def test_defaults_to_every_app(self) -> None:
assert cli._selected(None) == list(apps.APPS)
def test_keeps_registry_order(self) -> None:
assert cli._selected(["todo", "dufs_client"]) == ["dufs_client", "todo"]
class TestListCommand:
def test_prints_apps_and_glyphs(self, capsys: pytest.CaptureFixture[str]) -> None:
assert cli.main(["list"]) == 0
out = capsys.readouterr().out
assert "todo" in out
assert "checklist" in out
class TestPreviewCommand:
@patch(f"{MOD}.preview.build_contact_sheet")
def test_passes_output_path(
self, sheet: MagicMock, capsys: pytest.CaptureFixture[str], tmp_path: Path
) -> None:
target = tmp_path / "sheet.png"
sheet.return_value = target
assert cli.main(["preview", "--app", "todo", "-o", str(target)]) == 0
assert sheet.call_args.args == (["todo"], target)
assert str(target) in capsys.readouterr().out
class TestGenerateCommand:
@patch(f"{MOD}.render.safe_box_overflow", return_value=(0, 0))
@patch(f"{MOD}.generate.write_assets", return_value=[Path("a"), Path("b")])
def test_writes_assets_only_by_default(
self,
write: MagicMock,
mock_overflow: MagicMock,
capsys: pytest.CaptureFixture[str],
) -> None:
assert cli.main(["generate", "--app", "todo"]) == 0
assert write.call_count == 1
assert "wrote 2 asset files" in capsys.readouterr().out
@patch(f"{MOD}.render.safe_box_overflow", return_value=(12, 0))
@patch(f"{MOD}.generate.write_assets", return_value=[])
def test_warns_on_safe_box_overflow(
self,
mock_write: MagicMock,
mock_overflow: MagicMock,
capsys: pytest.CaptureFixture[str],
) -> None:
cli.main(["generate", "--app", "todo"])
assert "safe box" in capsys.readouterr().out
@patch(f"{MOD}.generate.run_flutter_launcher_icons")
@patch(f"{MOD}.render.safe_box_overflow", return_value=(0, 0))
@patch(f"{MOD}.generate.write_assets", return_value=[])
def test_android_flag_runs_generator(
self,
mock_write: MagicMock,
mock_overflow: MagicMock,
launcher: MagicMock,
) -> None:
cli.main(["generate", "--app", "todo", "--android"])
assert launcher.call_count == 1
@patch(f"{MOD}.generate.write_linux_icons", return_value=[Path("x")])
@patch(f"{MOD}.render.safe_box_overflow", return_value=(0, 0))
@patch(f"{MOD}.generate.write_assets", return_value=[])
def test_linux_out_only_for_linux_apps(
self,
mock_write: MagicMock,
mock_overflow: MagicMock,
linux: MagicMock,
tmp_path: Path,
) -> None:
cli.main(
[
"generate",
"--app",
"todo",
"--app",
"dufs_client",
"--linux-out",
str(tmp_path),
]
)
# The todo app has a Linux desktop target; dufs_client does not.
assert linux.call_count == 1
class TestParser:
def test_requires_a_subcommand(self) -> None:
with pytest.raises(SystemExit):
cli.main([])