2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
import pytest
|
2020-08-07 13:28:33 +03:00
|
|
|
|
2015-07-03 08:03:25 +03:00
|
|
|
from PIL import Image, XpmImagePlugin
|
2012-10-25 17:12:13 +04:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
from .helper import assert_image_similar, hopper
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2014-09-23 17:01:58 +04:00
|
|
|
TEST_FILE = "Tests/images/hopper.xpm"
|
2012-10-25 17:12:13 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
def test_sanity():
|
|
|
|
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)
|
2014-07-18 21:40:08 +04:00
|
|
|
|
2015-07-03 09:22:56 +03:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
def test_invalid_file():
|
|
|
|
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
|
|
|
|
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
def test_load_read():
|
|
|
|
# Arrange
|
|
|
|
with Image.open(TEST_FILE) as im:
|
|
|
|
dummy_bytes = 1
|
|
|
|
|
|
|
|
# Act
|
|
|
|
data = im.load_read(dummy_bytes)
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
assert len(data) == 16384
|