From c85acb865bbe68d76d42b4851b35f0e15741a34f Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Sun, 22 Nov 2026 20:52:11 +1000 Subject: [PATCH] fix: refuse a wildcard in Image.Read with its own error iread() returns (list of images, list of paths) for a wildcard, which Image.Read() took for a single image, so it failed an assert with a bare AssertionError and never reached its "wildcard read not supported" error. It now checks for the list and raises that ValueError. The xfail test that recorded the bug is now an ordinary test. Co-Authored-By: Claude Sonnet 5.5 --- src/machinevisiontoolbox/ImageIO.py | 5 +++++ tests/test_image_io_extra.py | 7 ------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/machinevisiontoolbox/ImageIO.py b/src/machinevisiontoolbox/ImageIO.py index ae60b246..dedc63eb 100644 --- a/src/machinevisiontoolbox/ImageIO.py +++ b/src/machinevisiontoolbox/ImageIO.py @@ -108,6 +108,11 @@ def Read( if isinstance(data, tuple): # singleton image, make it a list image_arr, name = data + if isinstance(image_arr, list): + # iread() returns (list of images, list of names) for a wildcard + raise ValueError( + "wildcard read not supported, use FileCollection instead" + ) assert isinstance(image_arr, np.ndarray) if not alpha and image_arr.ndim == 3 and image_arr.shape[2] == 4: image_arr = image_arr[:, :, :3] diff --git a/tests/test_image_io_extra.py b/tests/test_image_io_extra.py index 80fb154e..a239bb0d 100644 --- a/tests/test_image_io_extra.py +++ b/tests/test_image_io_extra.py @@ -51,13 +51,6 @@ def test_wildcard_that_matches_nothing_is_refused(self): with pytest.raises(ValueError, match="wildcard"): Image.Read("no-such-images-*.png") - @pytest.mark.xfail( - strict=True, - raises=AssertionError, - reason="iread() returns (list of images, list of paths) for a wildcard, " - "which Image.Read() mistakes for a single image, so its own " - "'wildcard read not supported' ValueError is never reached", - ) def test_wildcard_that_matches_files_is_refused(self): with pytest.raises(ValueError, match="wildcard"): Image.Read(str(DATA / "stripes*.png"))