mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 05:06:49 +03:00
Merge pull request #24 from hugovk/bgr-helper
Add deprecation helper for Image.new with BGR; modes
This commit is contained in:
commit
5736da80f1
|
@ -36,14 +36,19 @@ from .helper import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# 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:
|
class TestImage:
|
||||||
@pytest.mark.parametrize("mode", modes)
|
@pytest.mark.parametrize("mode", modes)
|
||||||
def test_image_modes_success(self, mode: str) -> None:
|
def test_image_modes_success(self, mode: str) -> None:
|
||||||
if mode.startswith("BGR;"):
|
helper_image_new(mode, (1, 1))
|
||||||
with pytest.warns(DeprecationWarning):
|
|
||||||
Image.new(mode, (1, 1))
|
|
||||||
else:
|
|
||||||
Image.new(mode, (1, 1))
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", ("", "bad", "very very long"))
|
@pytest.mark.parametrize("mode", ("", "bad", "very very long"))
|
||||||
def test_image_modes_fail(self, mode: str) -> None:
|
def test_image_modes_fail(self, mode: str) -> None:
|
||||||
|
@ -1039,11 +1044,7 @@ class TestImageBytes:
|
||||||
im = hopper(mode)
|
im = hopper(mode)
|
||||||
source_bytes = im.tobytes()
|
source_bytes = im.tobytes()
|
||||||
|
|
||||||
if mode.startswith("BGR;"):
|
reloaded = helper_image_new(mode, im.size)
|
||||||
with pytest.warns(DeprecationWarning):
|
|
||||||
reloaded = Image.new(mode, im.size)
|
|
||||||
else:
|
|
||||||
reloaded = Image.new(mode, im.size)
|
|
||||||
reloaded.frombytes(source_bytes)
|
reloaded.frombytes(source_bytes)
|
||||||
assert reloaded.tobytes() == source_bytes
|
assert reloaded.tobytes() == source_bytes
|
||||||
|
|
||||||
|
@ -1052,11 +1053,7 @@ class TestImageBytes:
|
||||||
if is_big_endian and mode == "BGR;15":
|
if is_big_endian and mode == "BGR;15":
|
||||||
pytest.xfail("Known failure of BGR;15 on big-endian")
|
pytest.xfail("Known failure of BGR;15 on big-endian")
|
||||||
im = hopper(mode)
|
im = hopper(mode)
|
||||||
if mode.startswith("BGR;"):
|
reloaded = helper_image_new(mode, im.size)
|
||||||
with pytest.warns(DeprecationWarning):
|
|
||||||
reloaded = Image.new(mode, im.size)
|
|
||||||
else:
|
|
||||||
reloaded = Image.new(mode, im.size)
|
|
||||||
reloaded.putdata(im.getdata())
|
reloaded.putdata(im.getdata())
|
||||||
assert_image_equal(im, reloaded)
|
assert_image_equal(im, reloaded)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user