- Shared moderated MP3 profile music (with floating mini-player and MediaSession controls, zero bubble when absent) - AI video dubbing into Russian with burned-in ASS subtitles inside AgentChat (`services/members/dub.py`) - Picture-in-Picture 9:16 and background audio playback (`PlayControl` + `play_patch.py`) - System/custom .ttf fonts & emoji packs (`FontsAndEmoji`), account cleaner (`AccountCleaner`) - Feed blacklist, muted sound restoration, OLED burn-in shift, A/B flag editor, presets, long comments - Updated site homepage (`src/web/index.html`) for LihonT 2.3.0 Serena
75 lines
3.3 KiB
Python
75 lines
3.3 KiB
Python
"""The black list of the feed (lihont.two.feed.Blacklist) on plain Java.
|
|
|
|
The matching has no Android in it, so javac and one run of a small harness cover every kind of rule;
|
|
the Android part (BlacklistStore, the call from FeedFilter) is checked as text, and the whole of the
|
|
mod's Java is compiled against android.jar by the build.
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SOURCES = ROOT / "src" / "lihont" / "two" / "feed"
|
|
HARNESS = ROOT / "tests" / "java" / "lihont" / "two" / "feed" / "BlacklistTest.java"
|
|
|
|
|
|
class BlacklistRulesTest(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("Blacklist tests require a JDK with java and javac")
|
|
cls.temporary = tempfile.TemporaryDirectory(prefix="lihont-blacklist-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)
|
|
command = [cls.javac, "--release", "17", "-encoding", "UTF-8", "-Xlint:all", "-Werror",
|
|
"-d", str(cls.classes), str(SOURCES / "Blacklist.java"), str(HARNESS)]
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding="utf-8",
|
|
env=cls.environment, timeout=120)
|
|
if result.returncode:
|
|
raise AssertionError("javac failed:\n%s%s" % (result.stdout, result.stderr))
|
|
|
|
def test_rules(self):
|
|
command = [self.java, "-Dfile.encoding=UTF-8", "-cp", str(self.classes), "lihont.two.feed.BlacklistTest"]
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding="utf-8",
|
|
env=self.environment, timeout=120)
|
|
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
self.assertEqual(result.stdout.strip(), "PASS")
|
|
|
|
|
|
class BlacklistHooksTest(unittest.TestCase):
|
|
"""The feed asks the list only when the person switched it on."""
|
|
|
|
def test_the_feed_filter_asks_the_black_list(self):
|
|
text = (SOURCES / "FeedFilter.java").read_text(encoding="utf-8")
|
|
self.assertIn("BlacklistStore.enabled(context)", text)
|
|
self.assertIn("isBlacklisted(item, blacklist)", text)
|
|
|
|
def test_the_filter_only_runs_when_the_list_is_on(self):
|
|
text = (SOURCES / "FeedFilter.java").read_text(encoding="utf-8")
|
|
self.assertIn("if (!ads && !live && !plugins && blacklist == null) return input;", text)
|
|
|
|
def test_the_switch_is_off_until_the_person_turns_it_on(self):
|
|
text = (SOURCES / "BlacklistStore.java").read_text(encoding="utf-8")
|
|
self.assertIn('getBoolean(KEY_ON, false)', text)
|
|
self.assertNotIn("java.net", text)
|
|
|
|
def test_the_settings_screen_edits_the_list(self):
|
|
text = (ROOT / "src" / "lihont" / "two" / "settings" / "LihonTSettingsActivity.java").read_text(
|
|
encoding="utf-8")
|
|
self.assertIn("blacklistRow()", text)
|
|
self.assertIn("BlacklistStore.save(this, lines)", text)
|
|
self.assertIn("BlacklistStore.setEnabled(this, toggle.isChecked())", text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|