From 90f709fb79f068338104fae7b50a7183976a5037 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Wed, 18 Sep 2024 18:16:06 -0500 Subject: [PATCH] parametrize test_histogram() --- Tests/test_image_histogram.py | 43 ++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/Tests/test_image_histogram.py b/Tests/test_image_histogram.py index dbd55d4c2..f6befc1dc 100644 --- a/Tests/test_image_histogram.py +++ b/Tests/test_image_histogram.py @@ -1,19 +1,36 @@ from __future__ import annotations +import pytest + +from PIL import Image + from .helper import hopper +expected_data = { + "1": (256, 0, 10994), + "CMYK": (1024, 0, 16384), + "F": (256, 0, 662), + "HSV": (768, 0, 1696), + "I": (256, 0, 662), + "I;16": (256, 0, 8192), + "I;16B": (256, 0, 8192), + "I;16L": (256, 0, 8192), + "I;16N": (256, 0, 8192), + "L": (256, 0, 662), + "LA": (512, 0, 662), + "La": (512, 0, 662), + "LAB": (768, 0, 1946), + "P": (256, 0, 1551), + "PA": (512, 0, 1551), + "RGB": (768, 4, 675), + "RGBA": (1024, 0, 16384), + "RGBa": (1024, 0, 16384), + "RGBX": (1024, 0, 16384), + "YCbCr": (768, 0, 1908), +} -def test_histogram() -> None: - def histogram(mode: str) -> tuple[int, int, int]: - h = hopper(mode).histogram() - return len(h), min(h), max(h) - assert histogram("1") == (256, 0, 10994) - assert histogram("L") == (256, 0, 662) - assert histogram("I") == (256, 0, 662) - assert histogram("F") == (256, 0, 662) - assert histogram("P") == (256, 0, 1551) - assert histogram("RGB") == (768, 4, 675) - assert histogram("RGBA") == (1024, 0, 16384) - assert histogram("CMYK") == (1024, 0, 16384) - assert histogram("YCbCr") == (768, 0, 1908) +@pytest.mark.parametrize("mode", Image.MODES) +def test_histogram(mode: str) -> None: + h = hopper(mode).histogram() + assert (len(h), min(h), max(h)) == expected_data[mode]