Pillow/Tests/test_file_xpm.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
862 B
Python
Raw Normal View History

from __future__ import annotations
2024-01-20 14:23:03 +03:00
2020-02-12 19:29:19 +03:00
import pytest
2015-07-03 08:03:25 +03:00
from PIL import Image, XpmImagePlugin
2020-02-12 19:29:19 +03:00
from .helper import assert_image_similar, hopper
2014-09-23 17:01:58 +04:00
TEST_FILE = "Tests/images/hopper.xpm"
2014-06-10 13:10:47 +04:00
2024-01-27 07:19:43 +03:00
def test_sanity() -> None:
2020-02-12 19:29:19 +03:00
with Image.open(TEST_FILE) as im:
im.load()
assert im.mode == "P"
assert im.size == (128, 128)
assert im.format == "XPM"
2019-11-25 23:03:23 +03:00
2020-02-12 19:29:19 +03:00
# large error due to quantization->44 colors.
assert_image_similar(im.convert("RGB"), hopper("RGB"), 60)
2015-07-03 09:22:56 +03:00
2024-01-27 07:19:43 +03:00
def test_invalid_file() -> None:
2020-02-12 19:29:19 +03:00
invalid_file = "Tests/images/flower.jpg"
2015-07-03 08:03:25 +03:00
2020-02-12 19:29:19 +03:00
with pytest.raises(SyntaxError):
XpmImagePlugin.XpmImageFile(invalid_file)
2014-07-17 03:38:57 +04:00
2024-01-27 07:19:43 +03:00
def test_load_read() -> None:
2020-02-12 19:29:19 +03:00
# Arrange
with Image.open(TEST_FILE) as im:
dummy_bytes = 1
# Act
data = im.load_read(dummy_bytes)
# Assert
assert len(data) == 16384