From 3c26f69f0c4a764c89cf3d3ce2452ba731475813 Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 02:32:18 +0100 Subject: [PATCH] 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 ef40bb5db..6f3dfd828 100644 --- a/tests/test_tile_probe.py +++ b/tests/test_tile_probe.py @@ -15,6 +15,11 @@ import unittest 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 @@ class TileProbeInputTest(unittest.TestCase): 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 @@ class TileProbeInputTest(unittest.TestCase): 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 @@ class TileProbeInputTest(unittest.TestCase): 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 @@ class TileProbeInputTest(unittest.TestCase): 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)