Pillow/Tests/test_image_fromqimage.py

61 lines
1.2 KiB
Python
Raw Normal View History

2020-03-27 11:50:51 +03:00
import pytest
from PIL import Image, ImageQt
2020-03-27 12:30:00 +03:00
from .helper import assert_image_equal, hopper
2020-03-27 11:50:51 +03:00
2020-03-28 04:51:28 +03:00
pytestmark = pytest.mark.skipif(
not ImageQt.qt_is_installed, reason="Qt bindings are not installed"
)
2020-03-27 11:50:51 +03:00
2020-03-27 12:30:00 +03:00
2020-03-27 11:50:51 +03:00
@pytest.fixture
def test_images():
ims = [
hopper(),
Image.open("Tests/images/transparent.png"),
Image.open("Tests/images/7x13.png"),
]
try:
yield ims
finally:
2020-03-28 04:51:28 +03:00
for im in ims:
2020-03-27 11:50:51 +03:00
im.close()
2020-03-27 12:30:00 +03:00
2020-03-27 11:50:51 +03:00
def roundtrip(expected):
# PIL -> Qt
intermediate = expected.toqimage()
# Qt -> PIL
result = ImageQt.fromqimage(intermediate)
if intermediate.hasAlphaChannel():
assert_image_equal(result, expected.convert("RGBA"))
else:
assert_image_equal(result, expected.convert("RGB"))
2020-03-27 12:30:00 +03:00
2020-03-27 11:50:51 +03:00
def test_sanity_1(test_images):
for im in test_images:
roundtrip(im.convert("1"))
2020-03-27 12:30:00 +03:00
2020-03-27 11:50:51 +03:00
def test_sanity_rgb(test_images):
for im in test_images:
roundtrip(im.convert("RGB"))
2020-03-27 12:30:00 +03:00
2020-03-27 11:50:51 +03:00
def test_sanity_rgba(test_images):
for im in test_images:
roundtrip(im.convert("RGBA"))
2020-03-27 12:30:00 +03:00
2020-03-27 11:50:51 +03:00
def test_sanity_l(test_images):
for im in test_images:
roundtrip(im.convert("L"))
2020-03-27 12:30:00 +03:00
2020-03-27 11:50:51 +03:00
def test_sanity_p(test_images):
for im in test_images:
roundtrip(im.convert("P"))