Pillow

Форк
0
/
test_file_mic.py 
75 строк · 1.8 Кб
1
from __future__ import annotations
2

3
import pytest
4

5
from PIL import Image, ImagePalette
6

7
from .helper import assert_image_similar, hopper, skip_unless_feature
8

9
MicImagePlugin = pytest.importorskip(
10
    "PIL.MicImagePlugin", reason="olefile not installed"
11
)
12
pytestmark = skip_unless_feature("libtiff")
13
TEST_FILE = "Tests/images/hopper.mic"
14

15

16
def test_sanity() -> None:
17
    with Image.open(TEST_FILE) as im:
18
        im.load()
19
        assert im.mode == "RGBA"
20
        assert im.size == (128, 128)
21
        assert im.format == "MIC"
22

23
        # Adjust for the gamma of 2.2 encoded into the file
24
        lut = ImagePalette.make_gamma_lut(1 / 2.2)
25
        im = Image.merge("RGBA", [chan.point(lut) for chan in im.split()])
26

27
        im2 = hopper("RGBA")
28
        assert_image_similar(im, im2, 10)
29

30

31
def test_n_frames() -> None:
32
    with Image.open(TEST_FILE) as im:
33
        assert im.n_frames == 1
34

35

36
def test_is_animated() -> None:
37
    with Image.open(TEST_FILE) as im:
38
        assert not im.is_animated
39

40

41
def test_tell() -> None:
42
    with Image.open(TEST_FILE) as im:
43
        assert im.tell() == 0
44

45

46
def test_seek() -> None:
47
    with Image.open(TEST_FILE) as im:
48
        im.seek(0)
49
        assert im.tell() == 0
50

51
        with pytest.raises(EOFError):
52
            im.seek(99)
53
        assert im.tell() == 0
54

55

56
def test_close() -> None:
57
    with Image.open(TEST_FILE) as im:
58
        pass
59
    assert im.ole.fp.closed
60

61
    im = Image.open(TEST_FILE)
62
    im.close()
63
    assert im.ole.fp.closed
64

65

66
def test_invalid_file() -> None:
67
    # Test an invalid OLE file
68
    invalid_file = "Tests/images/flower.jpg"
69
    with pytest.raises(SyntaxError):
70
        MicImagePlugin.MicImageFile(invalid_file)
71

72
    # Test a valid OLE file, but not a MIC file
73
    ole_file = "Tests/images/test-ole-file.doc"
74
    with pytest.raises(SyntaxError):
75
        MicImagePlugin.MicImageFile(ole_file)
76

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

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

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

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