Pillow/Tests/test_image_fromqimage.py

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

68 lines
1.4 KiB
Python
Raw Normal View History

from __future__ import annotations
2024-01-20 14:23:03 +03:00
import warnings
2020-03-27 11:50:51 +03:00
import pytest
from PIL import Image
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
from PIL import 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
ims: list[Image.Image] = []
2020-03-27 12:30:00 +03:00
2024-03-02 05:12:17 +03:00
def setup_module() -> None:
ims.append(hopper())
ims.append(Image.open("Tests/images/transparent.png"))
ims.append(Image.open("Tests/images/7x13.png"))
2024-03-02 05:12:17 +03:00
def teardown_module() -> None:
for im in ims:
im.close()
2020-03-27 11:50:51 +03:00
2020-03-27 12:30:00 +03:00
2024-01-25 14:18:46 +03:00
def roundtrip(expected: Image.Image) -> None:
2020-03-27 11:50:51 +03:00
# 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
2024-03-02 05:12:17 +03:00
def test_sanity_1() -> None:
for im in ims:
2020-03-27 11:50:51 +03:00
roundtrip(im.convert("1"))
2020-03-27 12:30:00 +03:00
2024-03-02 05:12:17 +03:00
def test_sanity_rgb() -> None:
for im in ims:
2020-03-27 11:50:51 +03:00
roundtrip(im.convert("RGB"))
2020-03-27 12:30:00 +03:00
2024-03-02 05:12:17 +03:00
def test_sanity_rgba() -> None:
for im in ims:
2020-03-27 11:50:51 +03:00
roundtrip(im.convert("RGBA"))
2020-03-27 12:30:00 +03:00
2024-03-02 05:12:17 +03:00
def test_sanity_l() -> None:
for im in ims:
2020-03-27 11:50:51 +03:00
roundtrip(im.convert("L"))
2020-03-27 12:30:00 +03:00
2024-03-02 05:12:17 +03:00
def test_sanity_p() -> None:
for im in ims:
2020-03-27 11:50:51 +03:00
roundtrip(im.convert("P"))