Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
tools: screendiff.py refuses an empty --out or --diff instead of writing no picture
xbsheng5e2f86c8fd24
diff --git a/tests/test_screendiff.py b/tests/test_screendiff.pyindex b0bc68ab0..47d095f3e 100644--- a/tests/test_screendiff.py+++ b/tests/test_screendiff.py@@ -310,6 +310,38 @@ class OutputPathTest(unittest.TestCase):self.assertIn(f"--out {out} has no extension", stderr)self.assertIn(f"name it {out}.png", stderr)+ def test_an_empty_out_is_refused_rather_than_read_as_no_pair(self):+ """`--out "$OUT"` with OUT unset asked for a pair: it used to compare and write none, with 0."""+ code, stdout, stderr = self.run_tool(["before.png", "after.png", "--out", ""])+ self.assertEqual(code, 2, "an empty --out must not read as 'no pair was asked for'")+ self.assertEqual(stdout, "")+ self.assertIn("--out was given as '', an empty name", stderr)+ self.assertIn("--out shots/before-after.png", stderr)+ self.assertIn("that variable was empty", stderr)+ self.assertIn("Nothing was read or written", stderr)+ self.assertNotIn("identical", stderr)+ self.assertNotIn("Traceback", stderr)++ def test_an_empty_diff_is_refused_the_same_way(self):+ code, stdout, stderr = self.run_tool(["before.png", "after.png", "--diff", ""])+ self.assertEqual(code, 2)+ self.assertEqual(stdout, "")+ self.assertIn("--diff was given as '', an empty name", stderr)+ self.assertIn("Nothing was read or written", stderr)++ def test_a_blank_out_is_refused_too(self):+ # `--out "$SPACE"` reads as no name at all once the shell has split it away.+ code, _, stderr = self.run_tool(["before.png", "after.png", "--out", " "])+ self.assertEqual(code, 2)+ self.assertIn("--out was given as ' ', an empty name", stderr)++ def test_the_option_left_out_is_still_no_pair(self):+ """Only an empty value is refused: leaving --out or --diff out is how a run writes neither."""+ self.assertIsNone(screendiff.output_path("--out", None))+ self.assertIsNone(screendiff.output_path("--diff", None))+ self.assertEqual(screendiff.output_path("--out", str(self.dir / "pair.png")),+ self.dir / "pair.png")+def test_the_paths_are_judged_before_the_screenshots_are_opened(self):# Neither argument exists, so anything that opened them would say so first.code, _, stderr = self.run_tool(["missing-before.png", "missing-after.png",diff --git a/tools/screendiff.md b/tools/screendiff.mdindex bb2be9583..32daa4b41 100644--- a/tools/screendiff.md+++ b/tools/screendiff.md@@ -13,7 +13,7 @@ tools/venv/bin/python tools/screendiff.py shots/before.png shots/after.png \|---|---|---|| 0 | `identical (1 region masked): ...` | No pixel outside the masks differs by more than 8 || 1 | `different: N pixels differ ..., inside x0,y0,x1,y1` | Find out why before posting |-| 2 | an error | Different sizes, a box outside the picture, an unreadable screenshot (the `before` or the `after` one is named, and a picture that was cut short counts), an `--out` or `--diff` it cannot write |+| 2 | an error | Different sizes, a box outside the picture, an unreadable screenshot (the `before` or the `after` one is named, and a picture that was cut short counts), an `--out` or `--diff` it cannot write, and one that was given an empty name - `--out "$OUT"` with `OUT` unset: leave the option out to compare without writing it || Option | Notes ||---|---|diff --git a/tools/screendiff.py b/tools/screendiff.pyindex 9fb47af12..e7baab7f0 100644--- a/tools/screendiff.py+++ b/tools/screendiff.py@@ -36,9 +36,21 @@ def output_path(option, path):Exit status 1 is 'the two screenshots differ', a finding the reader acts on, so a folder typed wrongmust not come back as one: --out and --diff are judged here, before the images are opened and beforePillow is imported, and a path that cannot be written is named rather than attempted.++ Left out is not the same as given empty. Both options are optional, so `--out "$OUT"` with OUT unset+ used to be dropped on the floor: the pair the run was asked to write was never written, nothing said+ so, and the run went on to report the comparison with 0 or 1 - the statuses that say the pictures were+ compared and, if they differ, nothing was. A name that came out empty is named here, with the way out,+ before anything is read."""- if not path:+ if path is None:return None+ if not path.strip():+ example = "--out shots/before-after.png" if option == "--out" else "--diff shots/diff.png"+ raise ValueError(f"{option} was given as {path!r}, an empty name, so no picture would be written: "+ f"name the file, e.g. {example} - and if the name came from a "+ f"shell variable, that variable was empty. Leave the option out to compare without "+ f"writing it")target = Path(path)if target.is_dir():raise ValueError(f"{option} {path} is a folder, so nothing could be written there: "