Files
LihonT/tests/test_auto_flame.py
cheb0chik eb4ae1cf25 LihonT 2 Luna pre-release 2
Streak widget from 1x1 to 4x4 with an animated flame (orange while lit, grey when not), a streak keeper that writes
the chosen message once a day to the chosen chats (off until switched on), avatar shapes, widgets and the keeper kept
per account, Material 3 tonal surfaces instead of black (AMOLED keeps pure black), launcher previews of our own, and
the mod runtime in a dex of its own.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 15:09:30 +03:00

88 lines
2.9 KiB
Python

"""Run the streak keeper's settings and day bookkeeping on a real JVM.
The book is plain Java (the Android parts only store it and send with it), so the tests compile it with
javac and run each scenario in its own process.
"""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
SOURCE = ROOT / "src" / "lihont" / "two" / "streak" / "AutoFlameBook.java"
HARNESS = ROOT / "tests" / "java" / "lihont" / "two" / "streak" / "AutoFlameBookTest.java"
class AutoFlameBookTest(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("Streak keeper tests require a JDK with java and javac")
cls.temporary = tempfile.TemporaryDirectory(prefix="lihont-streak-tests-")
cls.addClassCleanup(cls.temporary.cleanup)
cls.classes = Path(cls.temporary.name) / "classes"
cls.classes.mkdir()
cls.environment = dict(os.environ)
cls.environment.pop("JAVA_TOOL_OPTIONS", None)
cls.run_command([
cls.javac, "--release", "17", "-encoding", "UTF-8", "-Xlint:all", "-Werror",
"-d", str(cls.classes), str(SOURCE), str(HARNESS),
])
@classmethod
def run_command(cls, command):
result = subprocess.run(
command, capture_output=True, text=True, encoding="utf-8",
env=cls.environment, timeout=120,
)
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, "-Dfile.encoding=UTF-8", "-cp", str(self.classes),
"lihont.two.streak.AutoFlameBookTest", name,
])
self.assertEqual(result.stdout.strip(), "PASS " + name)
def test_defaults_are_off_noon_and_the_flame(self):
self.run_scenario("defaults")
def test_time_and_message_are_validated(self):
self.run_scenario("validation")
def test_chat_list_has_a_limit_and_an_order(self):
self.run_scenario("chats")
def test_next_trigger_is_the_next_chosen_time(self):
self.run_scenario("trigger")
def test_due_from_the_chosen_time_until_the_end_of_the_day(self):
self.run_scenario("due")
def test_a_chat_is_written_to_once_a_day(self):
self.run_scenario("perDay")
def test_the_change_of_the_clock_does_not_break_the_day(self):
self.run_scenario("clockChange")
def test_everything_survives_the_file(self):
self.run_scenario("roundTrip")
def test_a_damaged_file_loses_only_the_damaged_lines(self):
self.run_scenario("damaged")
if __name__ == "__main__":
unittest.main()