Files
lintunes/tests/test_round121.py
T
trav d93a265c33 v0.87.1: one app icon (lint.jpg, wave's corner radius) on desktop and andTunes 0.4.2; quitting no longer segfaults
The swap-a-PNG icon is gone: scripts/make_icons.py renders packaging/lint.jpg
into packaging/lintunes.png and the andTunes launcher. Quitting ends with
os._exit once aboutToQuit has saved everything — Python's teardown of the
QApplication wrapper segfaulted on every quit.
2026-11-06 02:01:06 -08:00

52 lines
2.1 KiB
Python

"""Round 121: one app icon (packaging/lint.jpg, wave's corner radius) on the
desktop and the Rabbit, and quitting no longer segfaults."""
from pathlib import Path
from unittest.mock import patch
from PyQt6.QtGui import QImage
from lintunes import main
ROOT = Path(__file__).resolve().parents[1]
DESKTOP = ROOT / "packaging" / "lintunes.png"
ANDROID = (ROOT / "andtunes" / "app" / "src" / "main" / "res"
/ "drawable-nodpi" / "ic_launcher.png")
def _alpha(img: QImage, x: int, y: int) -> int:
return img.pixelColor(x, y).alpha()
def test_both_icons_are_the_same_picture_with_round_corners(qapp):
desktop, android = QImage(str(DESKTOP)), QImage(str(ANDROID))
assert (desktop.width(), desktop.height()) == (512, 512)
assert (android.width(), android.height()) == (192, 192)
for img in (desktop, android):
side = img.width()
for x, y in ((0, 0), (side - 1, 0), (0, side - 1), (side - 1, side - 1)):
assert _alpha(img, x, y) == 0 # corners cut away
assert _alpha(img, side // 2, 0) == 255 # edges kept
assert _alpha(img, side // 2, side // 2) == 255
# Wave's radius, 16 % of the side: inside it the corner is still
# clear just off the diagonal, past it the picture is solid.
r = round(side * 0.16)
assert _alpha(img, round(r * 0.2), round(r * 0.2)) == 0
assert _alpha(img, r, 1) == 255
small = desktop.scaled(192, 192).convertToFormat(QImage.Format.Format_ARGB32)
a = android.convertToFormat(QImage.Format.Format_ARGB32)
mid = small.pixelColor(96, 96), a.pixelColor(96, 96)
assert all(abs(c1 - c2) < 24 for c1, c2 in zip(mid[0].getRgb(), mid[1].getRgb()))
def test_the_launcher_is_not_drawn_by_make_buttons():
src = (ROOT / "andtunes" / "tools" / "make_buttons.py").read_text()
assert "def launcher" not in src
def test_leave_flushes_and_skips_python_teardown():
with patch.object(main.os, "_exit") as hard_exit, \
patch("logging.shutdown") as log_shutdown:
main.leave(3)
log_shutdown.assert_called_once()
hard_exit.assert_called_once_with(3)