From ece34104cb0671ef0f1f59e9924fb1be0bcf351a Mon Sep 17 00:00:00 2001 From: Yay295 Date: Mon, 26 Feb 2024 00:34:54 -0600 Subject: [PATCH 1/3] parametrize test_p_from_rgb_rgba() --- Tests/test_image.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index 4c04e0da48e..ca4458f884d 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -685,15 +685,18 @@ def _make_new( _make_new(im, blank_p, ImagePalette.ImagePalette()) _make_new(im, blank_pa, ImagePalette.ImagePalette()) - def test_p_from_rgb_rgba(self) -> None: - for mode, color in [ + @pytest.mark.parametrize( + ("mode", "color"), + ( ("RGB", "#DDEEFF"), ("RGB", (221, 238, 255)), ("RGBA", (221, 238, 255, 255)), - ]: - im = Image.new("P", (100, 100), color) - expected = Image.new(mode, (100, 100), color) - assert_image_equal(im.convert(mode), expected) + ), + ) + def test_p_from_rgb_rgba(self, mode, color) -> None: + im = Image.new("P", (100, 100), color) + expected = Image.new(mode, (100, 100), color) + assert_image_equal(im.convert(mode), expected) def test_no_resource_warning_on_save(self, tmp_path: Path) -> None: # https://github.com/python-pillow/Pillow/issues/835 From fe85947f16f8f1e27a7416c4f0a0aec72be5b14e Mon Sep 17 00:00:00 2001 From: Yay295 Date: Mon, 26 Feb 2024 07:47:13 -0600 Subject: [PATCH 2/3] use single string for parameter names instead of tuple of strings Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- Tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index ca4458f884d..cdcbc707211 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -686,7 +686,7 @@ def _make_new( _make_new(im, blank_pa, ImagePalette.ImagePalette()) @pytest.mark.parametrize( - ("mode", "color"), + "mode, color", ( ("RGB", "#DDEEFF"), ("RGB", (221, 238, 255)), From e6785576b179fe730698d57d74c824c374b117ce Mon Sep 17 00:00:00 2001 From: Yay295 Date: Mon, 26 Feb 2024 08:47:30 -0600 Subject: [PATCH 3/3] add typing to test_p_from_rgb_rgba() Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Tests/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index cdcbc707211..2a4d453e2eb 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -693,7 +693,7 @@ def _make_new( ("RGBA", (221, 238, 255, 255)), ), ) - def test_p_from_rgb_rgba(self, mode, color) -> None: + def test_p_from_rgb_rgba(self, mode: str, color: str | tuple[int, ...]) -> None: im = Image.new("P", (100, 100), color) expected = Image.new(mode, (100, 100), color) assert_image_equal(im.convert(mode), expected)