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)