Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation helper for Image.new with BGR; modes #24

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@
)


# Deprecation helper
def helper_image_new(mode: str, size: tuple[int, int]) -> Image.Image:
if mode.startswith("BGR;"):
with pytest.warns(DeprecationWarning):
return Image.new(mode, size)
else:
return Image.new(mode, size)


class TestImage:
@pytest.mark.parametrize("mode", modes)
def test_image_modes_success(self, mode: str) -> None:
if mode.startswith("BGR;"):
with pytest.warns(DeprecationWarning):
Image.new(mode, (1, 1))
else:
Image.new(mode, (1, 1))
helper_image_new(mode, (1, 1))

@pytest.mark.parametrize("mode", ("", "bad", "very very long"))
def test_image_modes_fail(self, mode: str) -> None:
Expand Down Expand Up @@ -1039,11 +1044,7 @@ def test_roundtrip_bytes_method(self, mode: str) -> None:
im = hopper(mode)
source_bytes = im.tobytes()

if mode.startswith("BGR;"):
with pytest.warns(DeprecationWarning):
reloaded = Image.new(mode, im.size)
else:
reloaded = Image.new(mode, im.size)
reloaded = helper_image_new(mode, im.size)
reloaded.frombytes(source_bytes)
assert reloaded.tobytes() == source_bytes

Expand All @@ -1052,11 +1053,7 @@ 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")
im = hopper(mode)
if mode.startswith("BGR;"):
with pytest.warns(DeprecationWarning):
reloaded = Image.new(mode, im.size)
else:
reloaded = Image.new(mode, im.size)
reloaded = helper_image_new(mode, im.size)
reloaded.putdata(im.getdata())
assert_image_equal(im, reloaded)

Expand Down
Loading