Files
LihonT/tests/test_debug_mode.py
cheb0chik 8b7fa5ff57 LihonT 2 Serena alpha
Themes as data: the settings and the rest of TikTok take a look (Stickers, Windows 95, or a theme a plugin brings with the
right ui.theme); the DEBUG recovery mode (Clear cache in Android resets the look and puts the plugins in safe mode); new
plugin functions (name.style, confetti and buzz on a tap); a few memory trims in the chat bubbles; the person list for bubbles
no longer shows screen labels.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-02 12:32:37 +03:00

59 lines
3.1 KiB
Python

"""The recovery mode (DEBUG): the cache marker, the reset and where it is wired in, checked on the sources."""
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
TWO = ROOT / "src" / "lihont" / "two"
class DebugModeTest(unittest.TestCase):
def setUp(self):
self.source = (TWO / "look" / "DebugMode.java").read_text(encoding="utf-8")
def test_the_marker_lives_in_the_cache_so_clearing_the_cache_removes_it(self):
self.assertIn("getCacheDir()", self.source)
self.assertNotIn("getFilesDir()", self.source)
def test_a_missing_marker_with_debug_on_resets_the_look_and_the_plugins_once(self):
check = self.source[self.source.index("public static void check"):]
self.assertIn("if (!enabled(context)) return;", check)
self.assertIn("resetLook(context);", check)
self.assertIn("resetPlugins(context);", check)
# one shot: DEBUG turns itself off, so a cache the system trims later cannot reset anything twice
self.assertIn("set(context, false);", check)
def test_the_plugins_are_put_in_safe_mode_and_lose_the_internet_but_keep_their_files(self):
self.assertIn("PluginRegistry.enterSafeMode(context)", self.source)
self.assertIn("setNetOn(context, entry.id, false)", self.source)
self.assertNotIn("PluginRegistry.remove(", self.source)
def test_every_screen_checks_before_any_skin_reads_the_look(self):
windows = (TWO / "look" / "Windows.java").read_text(encoding="utf-8")
attach = windows[windows.index("public static void attach"):]
self.assertLess(attach.index("DebugMode.check(activity)"), attach.index("PluginScreen.attach"))
def test_the_settings_have_the_switch_and_explain_how_to_use_it(self):
screen = (TWO / "settings" / "LihonTSettingsActivity.java").read_text(encoding="utf-8")
self.assertIn("debugRow()", screen)
self.assertIn("Очистить кэш", screen)
self.assertIn('addSection("Восстановление"', screen)
def test_the_apps_own_restart_does_not_trigger_a_reset(self):
# the restart clears the cache; the marker must be put back, or every restart with DEBUG on would reset the look
screen = (TWO / "settings" / "LihonTSettingsActivity.java").read_text(encoding="utf-8")
clear = screen[screen.index("private void clearCache()"):]
clear = clear[:clear.index("private static boolean deleteRecursively")]
self.assertIn("DebugMode.keepMarker(this)", clear)
self.assertIn("public static void keepMarker", self.source)
def test_choosing_a_theme_always_offers_the_restart_so_old_and_new_paint_do_not_mix(self):
screen = (TWO / "settings" / "LihonTSettingsActivity.java").read_text(encoding="utf-8")
choose = screen[screen.index("private void chooseStyle()"):]
choose = choose[:choose.index("shown[0] = bubbleDialog")]
self.assertIn("showRestartNotice();", choose)
self.assertNotIn("if (repository.restartRequired()) showRestartNotice();", choose)
if __name__ == "__main__":
unittest.main()