Pillow/Tests/test_imagestat.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.2 KiB
Python
Raw Permalink Normal View History

from __future__ import annotations
2024-01-20 14:23:03 +03:00
import pytest
from PIL import Image, ImageStat
from .helper import hopper
def test_sanity() -> None:
im = hopper()
st = ImageStat.Stat(im)
st = ImageStat.Stat(im.histogram())
st = ImageStat.Stat(im, Image.new("1", im.size, 1))
# Check these run. Exceptions will cause failures.
st.extrema
st.sum
st.mean
st.median
st.rms
st.sum2
st.var
st.stddev
with pytest.raises(AttributeError):
2024-05-30 10:17:22 +03:00
st.spam() # type: ignore[attr-defined]
with pytest.raises(TypeError):
2024-05-30 10:17:22 +03:00
ImageStat.Stat(1) # type: ignore[arg-type]
def test_hopper() -> None:
im = hopper()
st = ImageStat.Stat(im)
# verify a few values
assert st.extrema[0] == (0, 255)
assert st.median[0] == 72
assert st.sum[0] == 1470218
assert st.sum[1] == 1311896
assert st.sum[2] == 1563008
2014-06-10 13:10:47 +04:00
def test_constant() -> None:
im = Image.new("L", (128, 128), 128)
st = ImageStat.Stat(im)
assert st.extrema[0] == (128, 128)
2022-03-04 08:42:24 +03:00
assert st.sum[0] == 128**3
assert st.sum2[0] == 128**4
assert st.mean[0] == 128
assert st.median[0] == 128
assert st.rms[0] == 128
assert st.var[0] == 0
assert st.stddev[0] == 0