From 3c26f69f0c4a764c89cf3d3ce2452ba731475813 Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 02:32:18 +0100 Subject: [PATCH 1/5] tests: tile_probe's numpy gate asks the way the tool runs HAVE_NUMPY used importlib.util.find_spec in this process, while the tests run the tool with python -I, which hides the --user install this machine has. The gate opened and four cases died on "needs numpy" instead of testing what they name. The file already did this correctly for Pillow (HAVE_PIL_ISOLATED); this applies the same probe to numpy and gates the four cases that reach it, keeping the eleven that test behaviour before numpy. Measured on main b8bd37111, Windows 11, Python 3.13: 5 failed, 12 passed before; 11 passed, 4 skipped after. Where -I sees numpy the probe returns true and the four run as before. Written with an AI assistant. --- tests/test_tile_probe.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_tile_probe.py b/tests/test_tile_probe.py index ef40bb5db2..6f3dfd828b 100644 --- a/tests/test_tile_probe.py +++ b/tests/test_tile_probe.py @@ -15,6 +15,11 @@ ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TOOL = os.path.join(ROOT, "tools", "tile_probe.py") HAVE_NUMPY = importlib.util.find_spec("numpy") is not None + +# The probe tests launch the tool with `python -I`, which does not see a --user install of numpy; ask the way it runs, +# as HAVE_PIL_ISOLATED below already does. Without this the gate opens and the child dies on a missing module. +NUMPY_VISIBLE_TO_TOOL = subprocess.run([sys.executable, "-I", "-c", "import numpy"], + capture_output=True, check=False).returncode == 0 # the tool is documented as `python -I`, which does not see a --user install of Pillow HAVE_PIL_ISOLATED = subprocess.run([sys.executable, "-I", "-c", "import PIL"], capture_output=True, check=False).returncode == 0 @@ -59,6 +64,7 @@ def test_offset_at_or_past_the_end_is_a_usage_error(self): self.assertNotIn("Traceback", p.stderr) self.assertEqual(p.stdout, "") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "the tool runs with -I, which cannot see this numpy") def test_empty_file_is_a_short_sample_not_a_bad_offset(self): empty = os.path.join(self.tmp.name, "empty.bin") open(empty, "wb").close() @@ -72,6 +78,7 @@ def test_empty_file_is_a_short_sample_not_a_bad_offset(self): self.assertIn("is past the end of blob", p.stderr) self.assertIn("(0 bytes)", p.stderr) + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "the tool runs with -I, which cannot see this numpy") def test_a_sample_with_no_candidate_layout_is_an_error(self): # Before: an 8-byte or 4 KiB blob printed nothing, wrote no preview and exited 0. tiny = os.path.join(self.tmp.name, "tiny.bin") @@ -120,6 +127,7 @@ def test_out_creates_a_missing_folder(self): self.assertTrue(os.path.isdir(os.path.dirname(preview)), "the preview's folder is created") @unittest.skipIf(HAVE_PIL_ISOLATED, "this interpreter's -I can import Pillow") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "the tool runs with -I, which cannot see this numpy") def test_preview_without_pillow_is_a_message_not_a_traceback(self): # Before: the probe ran, then render()'s lazy PIL import raised after all the work was done. p = self.run_tool(self.blob, "--out", os.path.join(self.tmp.name, "preview.png")) @@ -127,6 +135,7 @@ def test_preview_without_pillow_is_a_message_not_a_traceback(self): self.assertIn("Pillow", p.stderr) self.assertNotIn("Traceback", p.stderr) + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "the tool runs with -I, which cannot see this numpy") def test_offset_inside_the_file_still_probes(self): p = self.run_tool(self.blob, "--offset", "0") self.assertEqual(p.returncode, 0, p.stderr) From aa51a9693e49b938bfbe457e79bf301eed18380c Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 02:33:50 +0100 Subject: [PATCH 2/5] tests: swizzle_search's CLI gates ask the way the tool runs too The same in-process numpy check, in the file whose CLI tests spawn `python -I`: HAVE_NUMPY stayed for the tests that call numpy here, and the nine CLI gates now use NUMPY_VISIBLE_TO_TOOL, the isolated probe. Measured on main b8bd37111, Windows 11, Python 3.13: 3 failed, 23 passed, 5 skipped before; 21 passed, 10 skipped after. Where -I sees numpy the probe returns true and every gate opens as before. Written with an AI assistant. --- tests/test_swizzle_search.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/test_swizzle_search.py b/tests/test_swizzle_search.py index ad41b6e149..4965eeab12 100644 --- a/tests/test_swizzle_search.py +++ b/tests/test_swizzle_search.py @@ -27,6 +27,10 @@ except ImportError: HAVE_NUMPY = False +# The CLI tests launch the tool with `python -I`, which does not see a --user install of numpy; ask the way it runs. +# HAVE_NUMPY (this process) stays for the tests that call numpy directly. +NUMPY_VISIBLE_TO_TOOL = subprocess.run([sys.executable, "-I", "-c", "import numpy"], + capture_output=True, check=False).returncode == 0 try: from PIL import Image HAVE_PIL = True @@ -368,7 +372,7 @@ def test_search_empty_when_buffer_too_small(self): class TestSwizzleSearchCliAndRender(unittest.TestCase): - @unittest.skipUnless(HAVE_NUMPY and HAVE_PIL, "numpy and PIL required") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") def test_default_tile_target_previews_a_short_complete_row(self) -> None: with tempfile.TemporaryDirectory() as td: blob = Path(td) / "two_tiles.bin" @@ -388,7 +392,7 @@ def test_default_tile_target_previews_a_short_complete_row(self) -> None: expected_row = bytes((255, 0, 0)) * 32 + bytes((0, 255, 0)) * 32 self.assertEqual(image.tobytes(), expected_row * 32) - @unittest.skipUnless(HAVE_NUMPY, "numpy required") # the tool imports numpy before it parses arguments + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "numpy required") # the tool imports numpy before it parses arguments def test_cli_bad_numeric_arguments_are_usage_errors(self): """Bad --bpe/--tile/--widths/--tiles must be usage errors, not arithmetic tracebacks.""" cases = [ @@ -415,7 +419,7 @@ def test_cli_bad_numeric_arguments_are_usage_errors(self): self.assertIn(expected, result.stderr) self.assertNotIn("Traceback", result.stderr) - @unittest.skipUnless(HAVE_NUMPY, "numpy required") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "numpy required") def test_cli_missing_input_is_an_error_not_a_traceback(self): with tempfile.TemporaryDirectory() as tmp: missing = os.path.join(tmp, "definitely_missing_path") @@ -427,7 +431,7 @@ def test_cli_missing_input_is_an_error_not_a_traceback(self): self.assertIn("definitely_missing_path", result.stderr) self.assertNotIn("Traceback", result.stderr) - @unittest.skipUnless(HAVE_NUMPY, "numpy required") # the tool imports numpy before it parses arguments + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "numpy required") # the tool imports numpy before it parses arguments def test_preview_with_no_fitting_layout_reports_the_problem(self): """CLI with tiny blob and --out must exit 1, report 'no layout', and not create file.""" with tempfile.TemporaryDirectory() as td: @@ -444,7 +448,7 @@ def test_preview_with_no_fitting_layout_reports_the_problem(self): self.assertNotIn("Traceback", result.stderr) self.assertFalse(preview.exists()) - @unittest.skipUnless(HAVE_NUMPY, "numpy required") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "numpy required") def test_cli_successful_search_output(self): """CLI on valid synthetic buffer must exit 0 and print formatted scores and bit sequences.""" with tempfile.TemporaryDirectory() as td: @@ -473,7 +477,7 @@ def test_cli_successful_search_output(self): self.assertIn("bits(low->high)", result.stdout) self.assertNotIn("Traceback", result.stderr) - @unittest.skipUnless(HAVE_NUMPY and HAVE_PIL, "numpy and PIL required") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") def test_preview_rejects_input_and_hardlink_alias(self): """A preview must not overwrite the input or a hard link to it.""" for hardlink in (False, True): @@ -508,7 +512,7 @@ def test_preview_rejects_input_and_hardlink_alias(self): self.assertEqual(blob.read_bytes(), original) self.assertEqual(output.read_bytes(), original) - @unittest.skipUnless(HAVE_NUMPY and HAVE_PIL, "numpy and PIL required") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") def test_preview_ranks_thin_candidates_by_their_existing_edges(self) -> None: from PIL import Image @@ -531,7 +535,7 @@ def test_preview_ranks_thin_candidates_by_their_existing_edges(self) -> None: self.assertEqual(image.getcolors(), [(64, (0, 255, 0))]) self.assertNotIn("nan", result.stdout.lower()) - @unittest.skipUnless(HAVE_NUMPY and HAVE_PIL, "numpy and PIL required") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") def test_render_bc1_synthetic_output(self): """render() must decode synthetic BC1 data and save a valid PNG preview.""" with tempfile.TemporaryDirectory() as td: @@ -544,7 +548,7 @@ def test_render_bc1_synthetic_output(self): header = f.read(8) self.assertEqual(header, b"\x89PNG\r\n\x1a\n") - @unittest.skipUnless(HAVE_NUMPY and HAVE_PIL, "numpy and PIL required") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") def test_render_bc3_synthetic_output(self): """render() must decode synthetic BC3/BC10 data and save a valid PNG preview.""" with tempfile.TemporaryDirectory() as td: @@ -666,6 +670,7 @@ def test_render_valueerror_unknown_extension_returns_exit_2(self): self.assertNotIn("Traceback", err.getvalue()) +@unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "the tool runs with -I, which cannot see this numpy") def test_preview_with_no_fitting_layout_reports_the_problem(tmp_path=None): """Module-level compatibility wrapper for pytest with tmp_path fixture.""" if not HAVE_NUMPY: @@ -724,3 +729,4 @@ def test_missing_numpy_is_one_error_line(self): if __name__ == "__main__": unittest.main() + From 1eee5a1aaa709701fbc145ee5a681c8e27e4ea3e Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 04:04:04 +0100 Subject: [PATCH 3/5] tests: a sibling that imports a numeric tool is not a startup failure test_each_sibling_importing_tool_starts skipped a NUMERIC list when numpy was missing, but it asked find_spec in this process while the tools run with -I, so the skip never fired here; and a list of names cannot cover calibrated_texture and tex_export, which are not numeric themselves and import one that is. The probe now matches how the tools run, and a child that fails with "No module named 'numpy'" is skipped rather than failing the startup check. Measured on main b8bd37111, Windows 11, Python 3.13: 2 failed, 2 passed, 218 subtests before; 2 passed, 214 subtests after (the four are the two numpy-dependent subtests, skipped). With numpy visible to -I nothing changes. Written with an AI assistant. --- tests/test_tool_startup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_tool_startup.py b/tests/test_tool_startup.py index eb1eb65099..341f4cf33d 100644 --- a/tests/test_tool_startup.py +++ b/tests/test_tool_startup.py @@ -53,7 +53,10 @@ class ToolStartupTests(unittest.TestCase): def test_each_sibling_importing_tool_starts(self): paths = sibling_importers() self.assertGreater(len(paths), 20, "the sibling-import scan found almost nothing") - have_numpy = importlib.util.find_spec("numpy") is not None + # Ask the way the tools are launched: `-I` does not see a --user install, so find_spec in this process can + # say yes while the child gets ModuleNotFoundError (tests/test_tile_probe.py carries the same correction). + have_numpy = subprocess.run([sys.executable, "-I", "-c", "import numpy"], + capture_output=True, check=False).returncode == 0 for path in paths: name = os.path.splitext(os.path.basename(path))[0] if name in NUMERIC and not have_numpy: @@ -61,6 +64,10 @@ def test_each_sibling_importing_tool_starts(self): with self.subTest(tool=name): proc = subprocess.run([sys.executable, "-I", path, "--help"], capture_output=True, text=True, timeout=TIMEOUT, errors="replace") + # A sibling that is not numeric itself can still import a numeric one: a list of names cannot cover + # those, and a missing third-party module is not a startup failure. CI has numpy, so it never fires. + if not have_numpy and "No module named 'numpy'" in proc.stderr: + continue self.assertEqual(proc.returncode, 0, proc.stderr[-2000:]) self.assertNotIn("Traceback", proc.stderr) From b3b064bb79a3de7a3beeca4d5298074bd1325831 Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 04:13:49 +0100 Subject: [PATCH 4/5] tests: keep swizzle_search coverage when the user site is isolated Applied from merzleckeier's follow-up (f9456e020), unchanged: the two render() calls use the parent's numpy and Pillow, and the three CLI validation checks finish before the child needs numpy, so all five should run rather than skip. The two PNG preview subprocesses need Pillow in the child, which the isolated probe now checks. Written with an AI assistant. --- tests/test_swizzle_search.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/test_swizzle_search.py b/tests/test_swizzle_search.py index 4965eeab12..3acc64714c 100644 --- a/tests/test_swizzle_search.py +++ b/tests/test_swizzle_search.py @@ -31,6 +31,8 @@ # HAVE_NUMPY (this process) stays for the tests that call numpy directly. NUMPY_VISIBLE_TO_TOOL = subprocess.run([sys.executable, "-I", "-c", "import numpy"], capture_output=True, check=False).returncode == 0 +PIL_VISIBLE_TO_TOOL = subprocess.run([sys.executable, "-I", "-c", "from PIL import Image"], + capture_output=True, check=False).returncode == 0 try: from PIL import Image HAVE_PIL = True @@ -372,7 +374,7 @@ def test_search_empty_when_buffer_too_small(self): class TestSwizzleSearchCliAndRender(unittest.TestCase): - @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and PIL_VISIBLE_TO_TOOL and HAVE_PIL, "isolated numpy and PIL required") def test_default_tile_target_previews_a_short_complete_row(self) -> None: with tempfile.TemporaryDirectory() as td: blob = Path(td) / "two_tiles.bin" @@ -392,7 +394,6 @@ def test_default_tile_target_previews_a_short_complete_row(self) -> None: expected_row = bytes((255, 0, 0)) * 32 + bytes((0, 255, 0)) * 32 self.assertEqual(image.tobytes(), expected_row * 32) - @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "numpy required") # the tool imports numpy before it parses arguments def test_cli_bad_numeric_arguments_are_usage_errors(self): """Bad --bpe/--tile/--widths/--tiles must be usage errors, not arithmetic tracebacks.""" cases = [ @@ -419,7 +420,6 @@ def test_cli_bad_numeric_arguments_are_usage_errors(self): self.assertIn(expected, result.stderr) self.assertNotIn("Traceback", result.stderr) - @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL, "numpy required") def test_cli_missing_input_is_an_error_not_a_traceback(self): with tempfile.TemporaryDirectory() as tmp: missing = os.path.join(tmp, "definitely_missing_path") @@ -477,7 +477,6 @@ def test_cli_successful_search_output(self): self.assertIn("bits(low->high)", result.stdout) self.assertNotIn("Traceback", result.stderr) - @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") def test_preview_rejects_input_and_hardlink_alias(self): """A preview must not overwrite the input or a hard link to it.""" for hardlink in (False, True): @@ -512,7 +511,7 @@ def test_preview_rejects_input_and_hardlink_alias(self): self.assertEqual(blob.read_bytes(), original) self.assertEqual(output.read_bytes(), original) - @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") + @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and PIL_VISIBLE_TO_TOOL and HAVE_PIL, "isolated numpy and PIL required") def test_preview_ranks_thin_candidates_by_their_existing_edges(self) -> None: from PIL import Image @@ -535,7 +534,7 @@ def test_preview_ranks_thin_candidates_by_their_existing_edges(self) -> None: self.assertEqual(image.getcolors(), [(64, (0, 255, 0))]) self.assertNotIn("nan", result.stdout.lower()) - @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") + @unittest.skipUnless(HAVE_NUMPY and HAVE_PIL, "numpy and PIL required") def test_render_bc1_synthetic_output(self): """render() must decode synthetic BC1 data and save a valid PNG preview.""" with tempfile.TemporaryDirectory() as td: @@ -548,7 +547,7 @@ def test_render_bc1_synthetic_output(self): header = f.read(8) self.assertEqual(header, b"\x89PNG\r\n\x1a\n") - @unittest.skipUnless(NUMPY_VISIBLE_TO_TOOL and HAVE_PIL, "numpy and PIL required") + @unittest.skipUnless(HAVE_NUMPY and HAVE_PIL, "numpy and PIL required") def test_render_bc3_synthetic_output(self): """render() must decode synthetic BC3/BC10 data and save a valid PNG preview.""" with tempfile.TemporaryDirectory() as td: From dbd6ccc2ba1e49a39fee0008648673f531ea45d1 Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 15:47:21 +0100 Subject: [PATCH 5/5] tests: end the file with one newline, not two No content change. --- tests/test_swizzle_search.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_swizzle_search.py b/tests/test_swizzle_search.py index 3acc64714c..f797f7b5dd 100644 --- a/tests/test_swizzle_search.py +++ b/tests/test_swizzle_search.py @@ -728,4 +728,3 @@ def test_missing_numpy_is_one_error_line(self): if __name__ == "__main__": unittest.main() -