2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2023-01-08 15:37:46 +03:00
|
|
|
import pytest
|
|
|
|
|
2020-02-17 21:31:38 +03:00
|
|
|
from PIL import Image, ImageMode
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
from .helper import hopper
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_sanity() -> None:
|
2020-01-27 14:46:52 +03:00
|
|
|
with hopper() as im:
|
|
|
|
im.mode
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
ImageMode.getmode("1")
|
|
|
|
ImageMode.getmode("L")
|
|
|
|
ImageMode.getmode("P")
|
|
|
|
ImageMode.getmode("RGB")
|
|
|
|
ImageMode.getmode("I")
|
|
|
|
ImageMode.getmode("F")
|
2014-07-20 01:51:26 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
m = ImageMode.getmode("1")
|
|
|
|
assert m.mode == "1"
|
|
|
|
assert str(m) == "1"
|
|
|
|
assert m.bands == ("1",)
|
|
|
|
assert m.basemode == "L"
|
|
|
|
assert m.basetype == "L"
|
2022-02-15 10:01:02 +03:00
|
|
|
assert m.typestr == "|b1"
|
2014-07-20 01:51:26 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
for mode in (
|
|
|
|
"I;16",
|
|
|
|
"I;16S",
|
|
|
|
"I;16L",
|
|
|
|
"I;16LS",
|
|
|
|
"I;16B",
|
|
|
|
"I;16BS",
|
|
|
|
"I;16N",
|
|
|
|
"I;16NS",
|
|
|
|
):
|
|
|
|
m = ImageMode.getmode(mode)
|
|
|
|
assert m.mode == mode
|
|
|
|
assert str(m) == mode
|
|
|
|
assert m.bands == ("I",)
|
|
|
|
assert m.basemode == "L"
|
|
|
|
assert m.basetype == "L"
|
2019-06-12 13:33:00 +03:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
m = ImageMode.getmode("RGB")
|
|
|
|
assert m.mode == "RGB"
|
|
|
|
assert str(m) == "RGB"
|
|
|
|
assert m.bands == ("R", "G", "B")
|
|
|
|
assert m.basemode == "RGB"
|
|
|
|
assert m.basetype == "L"
|
2022-02-15 10:01:02 +03:00
|
|
|
assert m.typestr == "|u1"
|
2014-07-20 01:51:26 +04:00
|
|
|
|
2019-06-13 18:54:24 +03:00
|
|
|
|
2023-01-08 15:37:46 +03:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"mode, expected_base, expected_type, expected_bands, expected_band_names",
|
|
|
|
(
|
|
|
|
("1", "L", "L", 1, ("1",)),
|
|
|
|
("L", "L", "L", 1, ("L",)),
|
|
|
|
("P", "P", "L", 1, ("P",)),
|
|
|
|
("I", "L", "I", 1, ("I",)),
|
|
|
|
("F", "L", "F", 1, ("F",)),
|
|
|
|
("RGB", "RGB", "L", 3, ("R", "G", "B")),
|
|
|
|
("RGBA", "RGB", "L", 4, ("R", "G", "B", "A")),
|
|
|
|
("RGBX", "RGB", "L", 4, ("R", "G", "B", "X")),
|
|
|
|
("CMYK", "RGB", "L", 4, ("C", "M", "Y", "K")),
|
|
|
|
("YCbCr", "RGB", "L", 3, ("Y", "Cb", "Cr")),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
def test_properties(
|
|
|
|
mode, expected_base, expected_type, expected_bands, expected_band_names
|
2024-01-31 12:12:58 +03:00
|
|
|
) -> None:
|
2023-01-08 15:37:46 +03:00
|
|
|
assert Image.getmodebase(mode) == expected_base
|
|
|
|
assert Image.getmodetype(mode) == expected_type
|
|
|
|
assert Image.getmodebands(mode) == expected_bands
|
|
|
|
assert Image.getmodebandnames(mode) == expected_band_names
|