Pillow

Форк
0
/
test_file_blp.py 
78 строк · 2.3 Кб
1
from __future__ import annotations
2

3
from pathlib import Path
4

5
import pytest
6

7
from PIL import Image
8

9
from .helper import (
10
    assert_image_equal,
11
    assert_image_equal_tofile,
12
    assert_image_similar,
13
    hopper,
14
)
15

16

17
def test_load_blp1() -> None:
18
    with Image.open("Tests/images/blp/blp1_jpeg.blp") as im:
19
        assert_image_equal_tofile(im, "Tests/images/blp/blp1_jpeg.png")
20

21
    with Image.open("Tests/images/blp/blp1_jpeg2.blp") as im:
22
        im.load()
23

24

25
def test_load_blp2_raw() -> None:
26
    with Image.open("Tests/images/blp/blp2_raw.blp") as im:
27
        assert_image_equal_tofile(im, "Tests/images/blp/blp2_raw.png")
28

29

30
def test_load_blp2_dxt1() -> None:
31
    with Image.open("Tests/images/blp/blp2_dxt1.blp") as im:
32
        assert_image_equal_tofile(im, "Tests/images/blp/blp2_dxt1.png")
33

34

35
def test_load_blp2_dxt1a() -> None:
36
    with Image.open("Tests/images/blp/blp2_dxt1a.blp") as im:
37
        assert_image_equal_tofile(im, "Tests/images/blp/blp2_dxt1a.png")
38

39

40
def test_save(tmp_path: Path) -> None:
41
    f = str(tmp_path / "temp.blp")
42

43
    for version in ("BLP1", "BLP2"):
44
        im = hopper("P")
45
        im.save(f, blp_version=version)
46

47
        with Image.open(f) as reloaded:
48
            assert_image_equal(im.convert("RGB"), reloaded)
49

50
        with Image.open("Tests/images/transparent.png") as im:
51
            f = str(tmp_path / "temp.blp")
52
            im.convert("P").save(f, blp_version=version)
53

54
            with Image.open(f) as reloaded:
55
                assert_image_similar(im, reloaded, 8)
56

57
    im = hopper()
58
    with pytest.raises(ValueError):
59
        im.save(f)
60

61

62
@pytest.mark.parametrize(
63
    "test_file",
64
    [
65
        "Tests/images/timeout-060745d3f534ad6e4128c51d336ea5489182c69d.blp",
66
        "Tests/images/timeout-31c8f86233ea728339c6e586be7af661a09b5b98.blp",
67
        "Tests/images/timeout-60d8b7c8469d59fc9ffff6b3a3dc0faeae6ea8ee.blp",
68
        "Tests/images/timeout-8073b430977660cdd48d96f6406ddfd4114e69c7.blp",
69
        "Tests/images/timeout-bba4f2e026b5786529370e5dfe9a11b1bf991f07.blp",
70
        "Tests/images/timeout-d6ec061c4afdef39d3edf6da8927240bb07fe9b7.blp",
71
        "Tests/images/timeout-ef9112a065e7183fa7faa2e18929b03e44ee16bf.blp",
72
    ],
73
)
74
def test_crashes(test_file: str) -> None:
75
    with open(test_file, "rb") as f:
76
        with Image.open(f) as im:
77
            with pytest.raises(OSError):
78
                im.load()
79

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

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

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

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