2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2019-12-07 18:08:19 +03:00
|
|
|
from PIL import Image
|
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
from .helper import hopper
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
2024-01-25 14:18:46 +03:00
|
|
|
def test_sanity() -> None:
|
2020-01-27 14:46:52 +03:00
|
|
|
data = hopper().getdata()
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
len(data)
|
|
|
|
list(data)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
assert data[0] == (20, 20, 70)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
2024-01-25 14:18:46 +03:00
|
|
|
def test_roundtrip() -> None:
|
|
|
|
def getdata(mode: str) -> tuple[float | tuple[int, ...], int, int]:
|
2022-01-15 01:02:31 +03:00
|
|
|
im = hopper(mode).resize((32, 30), Image.Resampling.NEAREST)
|
2020-01-27 14:46:52 +03:00
|
|
|
data = im.getdata()
|
|
|
|
return data[0], len(data), len(list(data))
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
assert getdata("1") == (0, 960, 960)
|
|
|
|
assert getdata("L") == (17, 960, 960)
|
|
|
|
assert getdata("I") == (17, 960, 960)
|
|
|
|
assert getdata("F") == (17.0, 960, 960)
|
|
|
|
assert getdata("RGB") == ((11, 13, 52), 960, 960)
|
|
|
|
assert getdata("RGBA") == ((11, 13, 52, 255), 960, 960)
|
|
|
|
assert getdata("CMYK") == ((244, 242, 203, 0), 960, 960)
|
|
|
|
assert getdata("YCbCr") == ((16, 147, 123), 960, 960)
|