Pillow

Форк
0
/
test_lib_image.py 
34 строки · 912.0 Байт
1
from __future__ import annotations
2

3
import pytest
4

5
from PIL import Image
6

7

8
def test_setmode() -> None:
9
    im = Image.new("L", (1, 1), 255)
10
    im.im.setmode("1")
11
    assert im.im.getpixel((0, 0)) == 255
12
    im.im.setmode("L")
13
    assert im.im.getpixel((0, 0)) == 255
14

15
    im = Image.new("1", (1, 1), 1)
16
    im.im.setmode("L")
17
    assert im.im.getpixel((0, 0)) == 255
18
    im.im.setmode("1")
19
    assert im.im.getpixel((0, 0)) == 255
20

21
    im = Image.new("RGB", (1, 1), (1, 2, 3))
22
    im.im.setmode("RGB")
23
    assert im.im.getpixel((0, 0)) == (1, 2, 3)
24
    im.im.setmode("RGBA")
25
    assert im.im.getpixel((0, 0)) == (1, 2, 3, 255)
26
    im.im.setmode("RGBX")
27
    assert im.im.getpixel((0, 0)) == (1, 2, 3, 255)
28
    im.im.setmode("RGB")
29
    assert im.im.getpixel((0, 0)) == (1, 2, 3)
30

31
    with pytest.raises(ValueError):
32
        im.im.setmode("L")
33
    with pytest.raises(ValueError):
34
        im.im.setmode("RGBABCDE")
35

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

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

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

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