From 76a51270fa94ab1bf7f4b9e4212ad2e339023c2b Mon Sep 17 00:00:00 2001 From: nulano Date: Thu, 20 Aug 2020 23:16:19 +0200 Subject: [PATCH] split up test --- Tests/test_image_access.py | 49 ++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/Tests/test_image_access.py b/Tests/test_image_access.py index 17cb615a5..a4050b4d8 100644 --- a/Tests/test_image_access.py +++ b/Tests/test_image_access.py @@ -329,33 +329,36 @@ class TestCffi(AccessTest): class TestImagePutPixelError(AccessTest): - def test_putpixel_error_message(self): - for mode, reason, accept_tuple in [ - ("L", "color must be int or tuple", True), - ("LA", "color must be int or tuple", True), - ("RGB", "color must be int or tuple", True), - ("RGBA", "color must be int or tuple", True), - ("I", "color must be int", False), - ("I;16", "color must be int", False), - ("BGR;15", "color must be int", False), - ]: - im = hopper(mode) + IMAGE_MODES1 = ["L", "LA", "RGB", "RGBA"] + INVALID_TYPES1 = ["foo", 1.0, None] - for v in ["foo", 1.0, None]: - with pytest.raises(TypeError, match=reason): - im.putpixel((0, 0), v) + @pytest.mark.parametrize("mode", IMAGE_MODES1) + def test_putpixel_type_error1(self, mode): + im = hopper(mode) + for v in self.INVALID_TYPES1: + with pytest.raises(TypeError, match="color must be int or tuple"): + im.putpixel((0, 0), v) - if not accept_tuple: - with pytest.raises(TypeError, match=reason): - im.putpixel((0, 0), (10,)) + IMAGE_MODES2 = ["I", "I;16", "BGR;15"] + INVALID_TYPES2 = [*INVALID_TYPES1, (10,)] - with pytest.raises(OverflowError): - im.putpixel((0, 0), 2 ** 80) + @pytest.mark.parametrize("mode", IMAGE_MODES2) + def test_putpixel_type_error2(self, mode): + im = hopper(mode) + for v in self.INVALID_TYPES2: + with pytest.raises(TypeError, match="color must be int"): + im.putpixel((0, 0), v) - for mode in ["BGR;15"]: - im = hopper(mode) - with pytest.raises(ValueError, match="unrecognized image mode"): - im.putpixel((0, 0), 0) + @pytest.mark.parametrize("mode", IMAGE_MODES1 + IMAGE_MODES2) + def test_putpixel_overflow_error(self, mode): + im = hopper(mode) + with pytest.raises(OverflowError): + im.putpixel((0, 0), 2 ** 80) + + def test_putpixel_unrecognized_mode(self): + im = hopper("BGR;15") + with pytest.raises(ValueError, match="unrecognized image mode"): + im.putpixel((0, 0), 0) class TestEmbeddable: