Test unknown colour and missing colour key

This commit is contained in:
Andrew Murray 2025-04-10 21:59:04 +10:00
parent 34efaaddf3
commit dce9608961

View File

@ -33,12 +33,23 @@ def test_rgb() -> None:
assert_image_similar(im, hopper(), 16) assert_image_similar(im, hopper(), 16)
def test_cannot_read() -> None:
with open(TEST_FILE, "rb") as fp:
data = fp.read().split(b"#")[0]
with pytest.raises(ValueError, match="cannot read this XPM file"):
with Image.open(BytesIO(data)) as im:
pass
with pytest.raises(ValueError, match="cannot read this XPM file"):
with Image.open(BytesIO(data+b"invalid")) as im:
pass
def test_not_enough_image_data() -> None: def test_not_enough_image_data() -> None:
with open(TEST_FILE, "rb") as fp: with open(TEST_FILE, "rb") as fp:
data = fp.read().split(b"/* pixels */")[0] data = fp.read().split(b"/* pixels */")[0]
with Image.open(BytesIO(data)) as im: with Image.open(BytesIO(data)) as im:
with pytest.raises(ValueError, match="not enough image data"): with pytest.raises(ValueError, match="not enough image data"):
im.load() im.load()
def test_invalid_file() -> None: def test_invalid_file() -> None: