Files
LihonT/tests/test_frames.py
cheb0chik 9de69113b5 LihonT 2 Serena
LihonT Store: a separate app with a catalog of avatar frames and chat bubbles made by members (browse, add with "+", author
profiles, publishing), signed in through the TikTok that carries the mod (an exported no-window activity that answers only the
store, checked by package name and signing key). The mod gets frames made from any picture (a photo is cut into a ring), the
library of the store in the frame picker and for bubbles, other members' published bubbles and one picture per chat for both
people. The members service gets the catalog, the account library, uploads that are re-made with Pillow, an AI first pass
(Groq) and the owner's Telegram bot with accept and reject buttons. The build tools pass long file lists through an argument
file. Nothing a member sends is shown to others before it is approved.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 15:56:00 +03:00

101 lines
4.4 KiB
Python

"""Avatar frames: the catalog the mod downloads and the outline geometry, on a real JVM, and the catalog builder.
The catalog reader (FrameIndex) and the outline table (Outline) are plain Java, so they are compiled with javac and each scenario
runs in its own process. The parts that draw or download need a device; the runtime compile test covers that they build.
"""
import json
import os
import shutil
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SOURCES = [ROOT / "src" / "lihont" / "two" / "frame" / "FrameIndex.java",
ROOT / "src" / "lihont" / "two" / "frame" / "Outline.java",
ROOT / "src" / "lihont" / "two" / "frame" / "FrameCut.java",
ROOT / "src" / "lihont" / "two" / "plugin" / "Json.java",
ROOT / "src" / "lihont" / "two" / "plugin" / "LtpException.java"]
HARNESS = ROOT / "tests" / "java" / "lihont" / "two" / "frame" / "FrameTest.java"
class FrameJavaTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
javac, cls.java = shutil.which("javac"), shutil.which("java")
if not javac or not cls.java:
raise RuntimeError("Frame tests require a JDK with java and javac")
cls.temporary = tempfile.TemporaryDirectory(prefix="lihont-frame-tests-")
cls.addClassCleanup(cls.temporary.cleanup)
cls.classes = Path(cls.temporary.name)
env = dict(os.environ)
env.pop("JAVA_TOOL_OPTIONS", None)
cls.env = env
result = subprocess.run([javac, "--release", "17", "-encoding", "UTF-8", "-Xlint:all", "-Werror", "-d", str(cls.classes)]
+ [str(s) for s in SOURCES] + [str(HARNESS)],
capture_output=True, text=True, encoding="utf-8", env=env, timeout=120)
if result.returncode:
raise AssertionError(result.stdout + result.stderr)
def scenario(self, name):
result = subprocess.run([self.java, "-Dfile.encoding=UTF-8", "-cp", str(self.classes), "lihont.two.frame.FrameTest", name],
capture_output=True, text=True, encoding="utf-8", env=self.env, timeout=60, cwd=str(ROOT))
self.assertEqual(result.stdout.strip(), "PASS " + name, result.stdout + result.stderr)
def test_the_real_catalog_is_read(self):
self.scenario("real")
def test_bad_catalogs_are_refused(self):
self.scenario("refusals")
def test_bad_entries_are_dropped_and_good_ones_kept(self):
self.scenario("dropped")
def test_ids_names_and_mirrors(self):
self.scenario("ids")
def test_the_outline_geometry(self):
self.scenario("outline")
def test_a_part_can_sit_on_the_middle(self):
self.scenario("center")
def test_pictures_become_frames(self):
self.scenario("cut")
class CatalogBuilderTest(unittest.TestCase):
def test_the_catalog_is_up_to_date(self):
result = subprocess.run([sys.executable, "-X", "utf8", "-B", str(ROOT / "scripts" / "build_frames_catalog.py"), "--check"],
capture_output=True, text=True, encoding="utf-8", timeout=60)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
def test_every_sprite_matches_its_checksum_and_stays_small(self):
import hashlib
catalog = json.loads((ROOT / "frames" / "index.json").read_text(encoding="utf-8"))
total = 0
for pack in catalog["packs"]:
for sprite in pack["sprites"]:
data = (ROOT / "frames" / sprite["file"]).read_bytes()
self.assertEqual(hashlib.sha256(data).hexdigest(), sprite["sha256"], sprite["file"])
self.assertEqual(len(data), sprite["bytes"], sprite["file"])
self.assertLessEqual(len(data), 150 * 1024)
total += len(data)
self.assertLess(total, 400 * 1024, "the whole basic pack should stay a small download")
def test_every_frame_uses_sprites_of_its_pack_only(self):
catalog = json.loads((ROOT / "frames" / "index.json").read_text(encoding="utf-8"))
for pack in catalog["packs"]:
known = {s["file"] for s in pack["sprites"]}
for frame in pack["frames"]:
for part in frame["parts"]:
self.assertIn(part["file"], known)
self.assertTrue(part["file"].startswith(pack["id"] + "/"))
if __name__ == "__main__":
unittest.main()