"""The mod's icons are standard Material glyphs parsed from SVG path data. The parser and the icon table run on a desktop JVM; Android is only on the classpath. To look at the icons, render them with the harness: java -cp ;tools/android.jar lihont.two.settings.IconRenderTest render out.png """ import os from pathlib import Path import shutil import subprocess import tempfile import unittest ROOT = Path(__file__).resolve().parents[1] PACKAGE = ROOT / "src" / "lihont" / "two" / "settings" HARNESS = ROOT / "tests" / "java" / "lihont" / "two" / "settings" / "IconRenderTest.java" class IconTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.javac = shutil.which("javac") cls.java = shutil.which("java") if not cls.javac or not cls.java: raise RuntimeError("Icon tests require a JDK with java and javac") cls.android_jar = ROOT / "tools" / "android.jar" if not cls.android_jar.is_file(): raise RuntimeError("tools/android.jar must be available") cls.temporary = tempfile.TemporaryDirectory(prefix="lihont-icon-tests-") cls.addClassCleanup(cls.temporary.cleanup) cls.classes = Path(cls.temporary.name) cls.environment = dict(os.environ) cls.environment.pop("JAVA_TOOL_OPTIONS", None) cls.run_command([ cls.javac, "--release", "17", "-encoding", "UTF-8", "-nowarn", "-Xlint:-options", "-cp", str(cls.android_jar), "-d", str(cls.classes), str(PACKAGE / "SvgPath.java"), str(PACKAGE / "Md3Icon.java"), str(HARNESS), ]) @classmethod def run_command(cls, command): result = subprocess.run( command, capture_output=True, text=True, encoding="utf-8", env=cls.environment, timeout=60, ) if result.returncode: raise AssertionError( f"Command failed with exit {result.returncode}: {command[0]}\n" + result.stdout + result.stderr ) return result def run_scenario(self, name): result = self.run_command([ self.java, "-Djava.awt.headless=true", "-cp", str(self.classes) + os.pathsep + str(self.android_jar), "lihont.two.settings.IconRenderTest", name, ]) self.assertEqual(result.stdout.strip(), "PASS " + name) def test_every_icon_parses_inside_the_grid_and_is_legible(self): self.run_scenario("bounds") def test_path_data_shortcuts_and_arcs_are_understood(self): self.run_scenario("tokens") if __name__ == "__main__": unittest.main()