From dce96089614a2bfac112b5baa5f19d87874f526b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 10 Apr 2025 21:59:04 +1000 Subject: [PATCH] Test unknown colour and missing colour key --- Tests/test_file_xpm.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Tests/test_file_xpm.py b/Tests/test_file_xpm.py index 96365d7f4..de2d9bb79 100644 --- a/Tests/test_file_xpm.py +++ b/Tests/test_file_xpm.py @@ -33,12 +33,23 @@ def test_rgb() -> None: 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: with open(TEST_FILE, "rb") as fp: data = fp.read().split(b"/* pixels */")[0] - with Image.open(BytesIO(data)) as im: - with pytest.raises(ValueError, match="not enough image data"): - im.load() + with Image.open(BytesIO(data)) as im: + with pytest.raises(ValueError, match="not enough image data"): + im.load() def test_invalid_file() -> None: