mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-30 18:03:07 +03:00
Use a named tuple for the packed parameters
This commit is contained in:
parent
ac500460df
commit
6bf791a3e7
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any # undone
|
from typing import Any, NamedTuple
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -151,29 +151,37 @@ def test_lifetime2() -> None:
|
||||||
assert isinstance(px[0, 0], int)
|
assert isinstance(px[0, 0], int)
|
||||||
|
|
||||||
|
|
||||||
UINT_ARR = (
|
class DataShape(NamedTuple):
|
||||||
fl_uint8_4_type,
|
dtype: Any
|
||||||
[1,2,3,4],
|
elt: Any
|
||||||
1
|
elts_per_pixel: int
|
||||||
|
|
||||||
|
|
||||||
|
UINT_ARR = DataShape(
|
||||||
|
dtype=fl_uint8_4_type,
|
||||||
|
elt=[1, 2, 3, 4], # array of 4 uint 8 per pixel
|
||||||
|
elts_per_pixel=1, # only one array per pixel
|
||||||
)
|
)
|
||||||
UINT = (
|
|
||||||
pyarrow.uint8(),
|
UINT = DataShape(
|
||||||
3,
|
dtype=pyarrow.uint8(),
|
||||||
4
|
elt=3, # one uint8,
|
||||||
|
elts_per_pixel=4, # but repeated 4x per pixel
|
||||||
)
|
)
|
||||||
INT32 = (
|
|
||||||
pyarrow.uint32(),
|
UINT32 = DataShape(
|
||||||
0xabcdef45,
|
dtype=pyarrow.uint32(),
|
||||||
1
|
elt=0xABCDEF45, # one packed int, doesn't fit in a int32 > 0x80000000
|
||||||
|
elts_per_pixel=1, # one per pixel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mode, data_tp, mask",
|
"mode, data_tp, mask",
|
||||||
(
|
(
|
||||||
("L", (pyarrow.uint8(), 3, 1), None),
|
("L", DataShape(pyarrow.uint8(), 3, 1), None),
|
||||||
("I", (pyarrow.int32(), 1 << 24, 1), None),
|
("I", DataShape(pyarrow.int32(), 1 << 24, 1), None),
|
||||||
("F", (pyarrow.float32(), 3.14159, 1), None),
|
("F", DataShape(pyarrow.float32(), 3.14159, 1), None),
|
||||||
("LA", UINT_ARR, [0, 3]),
|
("LA", UINT_ARR, [0, 3]),
|
||||||
("LA", UINT, [0, 3]),
|
("LA", UINT, [0, 3]),
|
||||||
("RGB", UINT_ARR, [0, 1, 2]),
|
("RGB", UINT_ARR, [0, 1, 2]),
|
||||||
|
@ -188,7 +196,7 @@ INT32 = (
|
||||||
("HSV", UINT, [0, 1, 2]),
|
("HSV", UINT, [0, 1, 2]),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_fromarray(mode: str, data_tp: tuple, mask: list[int] | None) -> None:
|
def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
|
||||||
(dtype, elt, elts_per_pixel) = data_tp
|
(dtype, elt, elts_per_pixel) = data_tp
|
||||||
|
|
||||||
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
||||||
|
@ -201,15 +209,15 @@ def test_fromarray(mode: str, data_tp: tuple, mask: list[int] | None) -> None:
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mode, data_tp, mask",
|
"mode, data_tp, mask",
|
||||||
(
|
(
|
||||||
("LA", INT32, [0, 3]),
|
("LA", UINT32, [0, 3]),
|
||||||
("RGB", INT32, [0, 1, 2]),
|
("RGB", UINT32, [0, 1, 2]),
|
||||||
("RGBA", INT32, None),
|
("RGBA", UINT32, None),
|
||||||
("CMYK", INT32, None),
|
("CMYK", UINT32, None),
|
||||||
("YCbCr", INT32, [0, 1, 2]),
|
("YCbCr", UINT32, [0, 1, 2]),
|
||||||
("HSV", INT32, [0, 1, 2]),
|
("HSV", UINT32, [0, 1, 2]),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_from_int32array(mode: str, data_tp: tuple, mask: list[int] | None) -> None:
|
def test_from_int32array(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
|
||||||
(dtype, elt, elts_per_pixel) = data_tp
|
(dtype, elt, elts_per_pixel) = data_tp
|
||||||
|
|
||||||
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user