Skip to content

Commit

Permalink
Merge pull request python-pillow#8053 from radarhere/helper_modes
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed May 14, 2024
2 parents 60c94e6 + db4714c commit 0da83a1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 38 deletions.
27 changes: 0 additions & 27 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,6 @@
uploader = "github_actions"


modes = (
"1",
"L",
"LA",
"La",
"P",
"PA",
"F",
"I",
"I;16",
"I;16L",
"I;16B",
"I;16N",
"RGB",
"RGBA",
"RGBa",
"RGBX",
"BGR;15",
"BGR;16",
"BGR;24",
"CMYK",
"YCbCr",
"HSV",
"LAB",
)


def upload(a: Image.Image, b: Image.Image) -> str | None:
if uploader == "show":
# local img.show for errors.
Expand Down
9 changes: 4 additions & 5 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
is_big_endian,
is_win32,
mark_if_feature_version,
modes,
skip_unless_feature,
)

Expand All @@ -46,7 +45,7 @@ def helper_image_new(mode: str, size: tuple[int, int]) -> Image.Image:


class TestImage:
@pytest.mark.parametrize("mode", modes)
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
def test_image_modes_success(self, mode: str) -> None:
helper_image_new(mode, (1, 1))

Expand Down Expand Up @@ -1027,7 +1026,7 @@ def test_close_graceful(self, caplog: pytest.LogCaptureFixture) -> None:


class TestImageBytes:
@pytest.mark.parametrize("mode", modes)
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
def test_roundtrip_bytes_constructor(self, mode: str) -> None:
im = hopper(mode)
source_bytes = im.tobytes()
Expand All @@ -1039,7 +1038,7 @@ def test_roundtrip_bytes_constructor(self, mode: str) -> None:
reloaded = Image.frombytes(mode, im.size, source_bytes)
assert reloaded.tobytes() == source_bytes

@pytest.mark.parametrize("mode", modes)
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
def test_roundtrip_bytes_method(self, mode: str) -> None:
im = hopper(mode)
source_bytes = im.tobytes()
Expand All @@ -1048,7 +1047,7 @@ def test_roundtrip_bytes_method(self, mode: str) -> None:
reloaded.frombytes(source_bytes)
assert reloaded.tobytes() == source_bytes

@pytest.mark.parametrize("mode", modes)
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
def test_getdata_putdata(self, mode: str) -> None:
if is_big_endian() and mode == "BGR;15":
pytest.xfail("Known failure of BGR;15 on big-endian")
Expand Down
13 changes: 7 additions & 6 deletions Tests/test_image_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from PIL import Image

from .helper import assert_image_equal, hopper, is_win32, modes
from .helper import assert_image_equal, hopper, is_win32

# CFFI imports pycparser which doesn't support PYTHONOPTIMIZE=2
# https://github.com/eliben/pycparser/pull/198#issuecomment-317001670
Expand Down Expand Up @@ -205,12 +205,13 @@ def check(self, mode: str, expected_color_int: int | None = None) -> None:
with pytest.raises(error):
im.getpixel((-1, -1))

@pytest.mark.parametrize("mode", modes)
@pytest.mark.parametrize("mode", Image.MODES)
def test_basic(self, mode: str) -> None:
if mode.startswith("BGR;"):
with pytest.warns(DeprecationWarning):
self.check(mode)
else:
self.check(mode)

@pytest.mark.parametrize("mode", ("BGR;15", "BGR;16", "BGR;24"))
def test_deprecated(self, mode: str) -> None:
with pytest.warns(DeprecationWarning):
self.check(mode)

def test_list(self) -> None:
Expand Down

0 comments on commit 0da83a1

Please sign in to comment.