Parametrize some color_lut tests for DRYness

This commit is contained in:
Aarni Koskela 2024-08-06 15:19:40 +03:00
parent 71876cfd2a
commit 9d6d16d5cc

View File

@ -105,91 +105,68 @@ class TestColorLut3DCoreAPI:
with pytest.raises(TypeError): with pytest.raises(TypeError):
im.im.color_lut_3d("RGB", Image.Resampling.BILINEAR, 3, 2, 2, 2, 16) im.im.color_lut_3d("RGB", Image.Resampling.BILINEAR, 3, 2, 2, 2, 16)
def test_correct_args(self) -> None: @pytest.mark.parametrize(
("lut_mode", "table_size"),
[
("RGB", (3, 3)),
("CMYK", (4, 3)),
("RGB", (3, (2, 3, 3))),
("RGB", (3, (65, 3, 3))),
("RGB", (3, (3, 65, 3))),
("RGB", (3, (3, 3, 65))),
],
)
def test_correct_args(
self, lut_mode: str, table_size: tuple[int, int | tuple[int, int, int]]
) -> None:
im = Image.new("RGB", (10, 10), 0) im = Image.new("RGB", (10, 10), 0)
assert im.im is not None
im.im.color_lut_3d( im.im.color_lut_3d(
"RGB", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3) lut_mode,
)
im.im.color_lut_3d(
"CMYK", Image.Resampling.BILINEAR, *self.generate_identity_table(4, 3)
)
im.im.color_lut_3d(
"RGB",
Image.Resampling.BILINEAR, Image.Resampling.BILINEAR,
*self.generate_identity_table(3, (2, 3, 3)), *self.generate_identity_table(*table_size),
) )
@pytest.mark.parametrize(
("image_mode", "lut_mode", "table_size"),
[
("L", "RGB", (3, 3)),
("RGB", "L", (3, 3)),
("L", "L", (3, 3)),
("RGB", "RGBA", (3, 3)),
("RGB", "RGB", (4, 3)),
],
)
def test_wrong_mode(
self, image_mode: str, lut_mode: str, table_size: tuple[int, int]
) -> None:
with pytest.raises(ValueError, match="wrong mode"):
im = Image.new(image_mode, (10, 10), 0)
assert im.im is not None
im.im.color_lut_3d( im.im.color_lut_3d(
"RGB", lut_mode,
Image.Resampling.BILINEAR, Image.Resampling.BILINEAR,
*self.generate_identity_table(3, (65, 3, 3)), *self.generate_identity_table(*table_size),
) )
@pytest.mark.parametrize(
("image_mode", "lut_mode", "table_size"),
[
("RGBA", "RGB", (3, 3)),
("RGBA", "RGBA", (4, 3)),
("RGB", "HSV", (3, 3)),
("RGB", "RGBA", (4, 3)),
],
)
def test_correct_mode(
self, image_mode: str, lut_mode: str, table_size: tuple[int, int]
) -> None:
im = Image.new(image_mode, (10, 10), 0)
assert im.im is not None
im.im.color_lut_3d( im.im.color_lut_3d(
"RGB", lut_mode,
Image.Resampling.BILINEAR, Image.Resampling.BILINEAR,
*self.generate_identity_table(3, (3, 65, 3)), *self.generate_identity_table(*table_size),
)
im.im.color_lut_3d(
"RGB",
Image.Resampling.BILINEAR,
*self.generate_identity_table(3, (3, 3, 65)),
)
def test_wrong_mode(self) -> None:
with pytest.raises(ValueError, match="wrong mode"):
im = Image.new("L", (10, 10), 0)
im.im.color_lut_3d(
"RGB", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
)
with pytest.raises(ValueError, match="wrong mode"):
im = Image.new("RGB", (10, 10), 0)
im.im.color_lut_3d(
"L", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
)
with pytest.raises(ValueError, match="wrong mode"):
im = Image.new("L", (10, 10), 0)
im.im.color_lut_3d(
"L", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
)
with pytest.raises(ValueError, match="wrong mode"):
im = Image.new("RGB", (10, 10), 0)
im.im.color_lut_3d(
"RGBA", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
)
with pytest.raises(ValueError, match="wrong mode"):
im = Image.new("RGB", (10, 10), 0)
im.im.color_lut_3d(
"RGB", Image.Resampling.BILINEAR, *self.generate_identity_table(4, 3)
)
def test_correct_mode(self) -> None:
im = Image.new("RGBA", (10, 10), 0)
im.im.color_lut_3d(
"RGBA", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
)
im = Image.new("RGBA", (10, 10), 0)
im.im.color_lut_3d(
"RGBA", Image.Resampling.BILINEAR, *self.generate_identity_table(4, 3)
)
im = Image.new("RGB", (10, 10), 0)
im.im.color_lut_3d(
"HSV", Image.Resampling.BILINEAR, *self.generate_identity_table(3, 3)
)
im = Image.new("RGB", (10, 10), 0)
im.im.color_lut_3d(
"RGBA", Image.Resampling.BILINEAR, *self.generate_identity_table(4, 3)
) )
def test_identities(self) -> None: def test_identities(self) -> None: