Raise warning if image file identification fails due to lack of support

This commit is contained in:
Andrew Murray 2025-11-20 08:14:15 +11:00
parent e99989fde4
commit 099048b874
2 changed files with 5 additions and 5 deletions

View File

@ -23,8 +23,9 @@ class TestUnsupportedJpegXl:
monkeypatch.setattr(JpegXlImagePlugin, "SUPPORTED", False)
with pytest.raises(OSError):
with Image.open("Tests/images/hopper.jxl"):
pass
with pytest.warns(UserWarning, match="JXL support not installed"):
with Image.open("Tests/images/hopper.jxl"):
pass
@skip_unless_feature("jpegxl")

View File

@ -22,13 +22,12 @@ except ImportError:
# OPEN_COUNTS_FRAMES = True
def _accept(prefix: bytes) -> bool:
def _accept(prefix: bytes) -> bool | str:
is_jxl = prefix.startswith(
(b"\xff\x0a", b"\x00\x00\x00\x0c\x4a\x58\x4c\x20\x0d\x0a\x87\x0a")
)
if is_jxl and not SUPPORTED:
msg = "image file could not be identified because JXL support not installed"
raise SyntaxError(msg)
return "image file could not be identified because JXL support not installed"
return is_jxl