Skip to content

Commit

Permalink
enable bgr modes for image bytes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Mar 11, 2024
1 parent 12d626a commit 680f387
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,34 +1045,26 @@ def test_close_graceful(self, caplog: pytest.LogCaptureFixture) -> None:


class TestImageBytes:
# The BGR modes don't support the methods tested in this class.
image_modes_not_bgr = [mode for mode in image_modes if "BGR" not in mode[0]]
image_mode_names_not_bgr = [
name for name, num_bands, pixelsize in image_modes if "BGR" not in name
]

sample_bytes = bytes(
range(
2 * 2 * max(pixelsize for mode, num_bands, pixelsize in image_modes_not_bgr)
)
range(2 * 2 * max(pixelsize for mode, num_bands, pixelsize in image_modes))
)

@pytest.mark.parametrize("mode", image_mode_names_not_bgr)
@pytest.mark.parametrize("mode", image_mode_names)
def test_roundtrip_bytes_constructor(self, mode: str):
source_image = hopper(mode)
source_bytes = source_image.tobytes()
copy_image = Image.frombytes(mode, source_image.size, source_bytes)
assert copy_image.tobytes() == source_bytes

@pytest.mark.parametrize("mode", image_mode_names_not_bgr)
@pytest.mark.parametrize("mode", image_mode_names)
def test_roundtrip_bytes_method(self, mode: str):
source_image = hopper(mode)
source_bytes = source_image.tobytes()
copy_image = Image.new(mode, source_image.size)
copy_image.frombytes(source_bytes)
assert copy_image.tobytes() == source_bytes

@pytest.mark.parametrize(("mode", "num_bands", "pixelsize"), image_modes_not_bgr)
@pytest.mark.parametrize(("mode", "num_bands", "pixelsize"), image_modes)
def test_pixels_after_getdata_putdata(
self, mode: str, num_bands: int, pixelsize: int
):
Expand Down

0 comments on commit 680f387

Please sign in to comment.