Pillow

Форк
0
/
test_image_fromqimage.py 
67 строк · 1.4 Кб
1
from __future__ import annotations
2

3
import warnings
4

5
import pytest
6

7
from PIL import Image
8

9
with warnings.catch_warnings():
10
    warnings.simplefilter("ignore", category=DeprecationWarning)
11
    from PIL import ImageQt
12

13
from .helper import assert_image_equal, hopper
14

15
pytestmark = pytest.mark.skipif(
16
    not ImageQt.qt_is_installed, reason="Qt bindings are not installed"
17
)
18

19
ims: list[Image.Image] = []
20

21

22
def setup_module() -> None:
23
    ims.append(hopper())
24
    ims.append(Image.open("Tests/images/transparent.png"))
25
    ims.append(Image.open("Tests/images/7x13.png"))
26

27

28
def teardown_module() -> None:
29
    for im in ims:
30
        im.close()
31

32

33
def roundtrip(expected: Image.Image) -> None:
34
    # PIL -> Qt
35
    intermediate = expected.toqimage()
36
    # Qt -> PIL
37
    result = ImageQt.fromqimage(intermediate)
38

39
    if intermediate.hasAlphaChannel():
40
        assert_image_equal(result, expected.convert("RGBA"))
41
    else:
42
        assert_image_equal(result, expected.convert("RGB"))
43

44

45
def test_sanity_1() -> None:
46
    for im in ims:
47
        roundtrip(im.convert("1"))
48

49

50
def test_sanity_rgb() -> None:
51
    for im in ims:
52
        roundtrip(im.convert("RGB"))
53

54

55
def test_sanity_rgba() -> None:
56
    for im in ims:
57
        roundtrip(im.convert("RGBA"))
58

59

60
def test_sanity_l() -> None:
61
    for im in ims:
62
        roundtrip(im.convert("L"))
63

64

65
def test_sanity_p() -> None:
66
    for im in ims:
67
        roundtrip(im.convert("P"))
68

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.