Pillow/Tests/test_file_xpm.py

38 lines
802 B
Python
Raw Normal View History

2020-02-12 19:29:19 +03:00
import pytest
2020-09-01 20:16:46 +03:00
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
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)
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