testsAndMisc/python_pkg/app_icons/tests/test_main_entry.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

35 lines
1.3 KiB
Python

"""Tests for app_icons.__main__ module."""
from __future__ import annotations
import importlib
import runpy
import sys
from unittest.mock import MagicMock, patch
import pytest
class TestMain:
def test_main_called_when_run_as_module(self) -> None:
"""python3 -m python_pkg.app_icons runs main() and exits with its status."""
mock_main = MagicMock(return_value=0)
# runpy warns if __main__ is already imported, and the suite runs tests
# in a random order, so another test may have imported it first.
sys.modules.pop("python_pkg.app_icons.__main__", None)
with (
patch("python_pkg.app_icons.cli.main", mock_main),
pytest.raises(SystemExit) as excinfo,
):
runpy.run_module("python_pkg.app_icons", run_name="__main__")
assert excinfo.value.code == 0
mock_main.assert_called_once()
def test_main_not_called_on_plain_import(self) -> None:
"""Importing __main__ must not generate icons as a side effect."""
mock_main = MagicMock()
with patch("python_pkg.app_icons.cli.main", mock_main):
sys.modules.pop("python_pkg.app_icons.__main__", None)
importlib.import_module("python_pkg.app_icons.__main__")
mock_main.assert_not_called()