Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

tools/manage.py: stop when the TV doesn't answer instead of reporting an empty TV

מקס חיים2b62fb6a68a2
diff --git a/tests/test_manage.py b/tests/test_manage.py
index a42e64f67..943e42bcc 100644
--- a/tests/test_manage.py
+++ b/tests/test_manage.py
@@ -1,7 +1,12 @@
"""tools/manage.py reads the add-ons, themes and switches from the repo's own READMEs; check it finds them all, and
that every add-on has a way in: its own install script or the steps in addons/README.md."""
+import contextlib
+import io
+import os
+import subprocess
import sys
import unittest
+from unittest import mock
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
@@ -43,5 +48,40 @@ class ManageTest(unittest.TestCase):
manage.cmd_set("columns", "6", str(ROOT / "themes" / "aurora"))
+ def status(self, *answers):
+ """Runs `status` with tv.py's answers (stdout, returncode, stderr) in order; returns what it printed."""
+ replies = iter(subprocess.CompletedProcess([], code, out, err) for out, code, err in answers)
+ out = io.StringIO()
+ with mock.patch.dict(os.environ, {"TV_HOST": "192.0.2.1"}), \
+ mock.patch.object(manage, "tv_python", return_value="python3"), \
+ mock.patch.object(manage.subprocess, "run", side_effect=lambda *a, **k: next(replies)), \
+ contextlib.redirect_stdout(out):
+ code = manage.main(["status"])
+ return code, out.getvalue()
+
+ def test_status_stops_when_the_tv_does_not_answer(self):
+ for answers, message in [
+ ([("", 1, "failed to connect")], "failed to connect"),
+ ([("package:com.a\n", 1, "")], "package:com.a"),
+ ([("", 255, "")], "tv.py exited with status 255"),
+ ([("", 0, ""), ("", 1, "unauthorized")], "unauthorized"),
+ ]:
+ with self.subTest(message=message), self.assertRaises(SystemExit) as stop:
+ self.status(*answers)
+ self.assertEqual(stop.exception.code, message)
+
+ def test_status_reads_an_empty_tv(self):
+ code, out = self.status(("", 0, ""), ("", 0, ""))
+ self.assertEqual(code, 0)
+ self.assertIn("launcher: not installed", out)
+ self.assertIn("theme: none", out)
+
+ def test_status_finds_the_launcher_and_a_theme(self):
+ theme = ROOT / "themes" / manage.themes()[0]["id"] / "config.json"
+ code, out = self.status(("package:" + manage.LAUNCHER_PKG + "\n", 0, ""), (theme.read_text(encoding="utf-8"), 0, ""))
+ self.assertEqual(code, 0)
+ self.assertIn("launcher: installed", out)
+ self.assertIn("theme: " + manage.themes()[0]["id"], out)
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/manage.py b/tools/manage.py
index dd9ca309f..0e9c00c89 100644
--- a/tools/manage.py
+++ b/tools/manage.py
@@ -147,6 +147,9 @@ def tv(command):
if not os.environ.get("TV_HOST"):
sys.exit("set TV_HOST to the TV IP address")
r = subprocess.run([tv_python(), "-I", str(TOOLS / "tv.py"), command], capture_output=True, text=True)
+ # A failed read is unknown, not empty: never report "not installed" for a TV that didn't answer.
+ if r.returncode:
+ sys.exit(r.stderr.strip() or r.stdout.strip() or f"tv.py exited with status {r.returncode}")
return r.stdout