Skip to content

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

tests: the unreached-TV suites skip without the client packages, not fail

xbsheng2f55c0dc064e
diff --git a/tests/test_privacy_unreached_tv.py b/tests/test_privacy_unreached_tv.py
index fbb46fa27..85a49a788 100644
--- a/tests/test_privacy_unreached_tv.py
+++ b/tests/test_privacy_unreached_tv.py
@@ -18,6 +18,10 @@ and an empty stdout now, and a `--write` target is still not created.
The last test is the branch that was already right: a checkout with no tools/tv.py at all still says
it could not load it, with 2.
+The four runs that start the checkout's own tv.py skip when this interpreter cannot import adb_shell,
+which that copy needs: the suite has to stay green under `python3 -m unittest discover -s tests -v`, the
+command each docs/workflows/ page ends with, on a machine that never installed tools/requirements.txt.
+
Run from the repository root: python3 -m unittest discover -s tests -v
"""
import os
@@ -36,9 +40,26 @@ BAD_PORT = "not a port number: 'abc'"
CANNOT_LOAD = "cannot load tools/tv.py"
+def packages_installed():
+ """True when this interpreter can load adb_shell, which the checkout's tv.py needs to be imported."""
+ return subprocess.run([sys.executable, "-c", "import adb_shell"],
+ capture_output=True, timeout=120).returncode == 0
+
+
class PrivacyNeedsHostTest(unittest.TestCase):
"""The checkout's own tools/tv.py: the two refusals it makes while it is being imported."""
+ @classmethod
+ def setUpClass(cls):
+ # Without adb_shell the copy of tv.py stops at its own import, so these four runs would see
+ # "cannot load tools/tv.py" instead of the refusal they are about - and the suite would report
+ # failures rather than the skip the rest of the unreached-TV files give (the bench.py,
+ # b64push.py and recovery.py ones). `python3 -m unittest discover -s tests -v`, the command each
+ # docs/workflows/ page ends with, runs on a machine that never installed tools/requirements.txt.
+ if not packages_installed():
+ raise unittest.SkipTest("needs the packages tools/venv installs (pip install -r "
+ "tools/requirements.txt)")
+
def setUp(self):
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
diff --git a/tests/test_trace_unreached_tv.py b/tests/test_trace_unreached_tv.py
index 9fbd9fb84..bfbcff625 100644
--- a/tests/test_trace_unreached_tv.py
+++ b/tests/test_trace_unreached_tv.py
@@ -17,7 +17,9 @@ The reader here is the checkout's own tools/tv.py, copied beside a copy of trace
imports it from), and the stub cases pin the handler around it: a client module that stops with its own
text (2, that text printed), one that stops with a number (2, since nothing was recorded) and one that
exits 0 (its status stands - the branch tools/theme_restart.py keeps). A TV that answered keeps 1: it was
-reached, and the docstring's 1 covers what happens next.
+reached, and the docstring's 1 covers what happens next. Both classes need the packages
+tools/requirements.txt installs - the second one because trace.py looks for adb_shell before it imports
+tv at all - so each skips with a reason on an interpreter without them, rather than failing.
Run from the repository root: python3 -m unittest discover -s tests -v
"""
@@ -114,6 +116,17 @@ class RealClientTest(Base):
class StubClientTest(Base):
"""The handler around `import tv` itself: a client module that decides to stop while imported."""
+ @classmethod
+ def setUpClass(cls):
+ # The stub stands in for tv.py, but trace.py checks for adb_shell before it imports anything
+ # (client_python_or_exit(), the line that builds the venv), so these four runs need the packages
+ # too: without them every one of them read "trace.py needs the packages" instead of the exit its
+ # test is about, and the file came out as four failures on a machine that never installed
+ # tools/requirements.txt rather than the skip RealClientTest above it gives.
+ if not packages_installed():
+ raise unittest.SkipTest("needs the packages tools/venv installs (pip install -r "
+ "tools/requirements.txt)")
+
def test_a_client_that_stops_with_its_own_words_prints_them_and_answers_2(self):
self.stub('raise SystemExit("the client refuses this TV")\n')
result = self.run_trace(TV_HOST="192.0.2.9")