Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 7 additions & 11 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,13 @@ def _cached_hopper(mode: str) -> Image.Image:
im = hopper("L")
else:
im = hopper()
if mode.startswith("BGR;"):
with pytest.warns(DeprecationWarning, match="BGR;"):
im = im.convert(mode)
else:
try:
im = im.convert(mode)
except ImportError:
if mode == "LAB":
im = Image.open("Tests/images/hopper.Lab.tif")
else:
raise
try:
im = im.convert(mode)
except ImportError:
if mode == "LAB":
im = Image.open("Tests/images/hopper.Lab.tif")
else:
raise
return im


Expand Down
20 changes: 10 additions & 10 deletions Tests/test_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"version, expected",
[
(
12,
"Old thing is deprecated and will be removed in Pillow 12 "
r"\(2025-10-15\)\. Use new thing instead\.",
13,
"Old thing is deprecated and will be removed in Pillow 13 "
r"\(2026-10-15\)\. Use new thing instead\.",
),
(
None,
Expand Down Expand Up @@ -53,18 +53,18 @@ def test_old_version(deprecated: str, plural: bool, expected: str) -> None:

def test_plural() -> None:
expected = (
r"Old things are deprecated and will be removed in Pillow 12 \(2025-10-15\)\. "
r"Old things are deprecated and will be removed in Pillow 13 \(2026-10-15\)\. "
r"Use new thing instead\."
)
with pytest.warns(DeprecationWarning, match=expected):
_deprecate.deprecate("Old things", 12, "new thing", plural=True)
_deprecate.deprecate("Old things", 13, "new thing", plural=True)


def test_replacement_and_action() -> None:
expected = "Use only one of 'replacement' and 'action'"
with pytest.raises(ValueError, match=expected):
_deprecate.deprecate(
"Old thing", 12, replacement="new thing", action="Upgrade to new thing"
"Old thing", 13, replacement="new thing", action="Upgrade to new thing"
)


Expand All @@ -77,16 +77,16 @@ def test_replacement_and_action() -> None:
)
def test_action(action: str) -> None:
expected = (
r"Old thing is deprecated and will be removed in Pillow 12 \(2025-10-15\)\. "
r"Old thing is deprecated and will be removed in Pillow 13 \(2026-10-15\)\. "
r"Upgrade to new thing\."
)
with pytest.warns(DeprecationWarning, match=expected):
_deprecate.deprecate("Old thing", 12, action=action)
_deprecate.deprecate("Old thing", 13, action=action)


def test_no_replacement_or_action() -> None:
expected = (
r"Old thing is deprecated and will be removed in Pillow 12 \(2025-10-15\)"
r"Old thing is deprecated and will be removed in Pillow 13 \(2026-10-15\)"
)
with pytest.warns(DeprecationWarning, match=expected):
_deprecate.deprecate("Old thing", 12)
_deprecate.deprecate("Old thing", 13)
15 changes: 0 additions & 15 deletions Tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,6 @@ def test(name: str, function: Callable[[str], str | None]) -> None:
test(feature, features.version_feature)


def test_webp_transparency() -> None:
with pytest.warns(DeprecationWarning, match="transp_webp"):
assert (features.check("transp_webp") or False) == features.check_module("webp")


def test_webp_mux() -> None:
with pytest.warns(DeprecationWarning, match="webp_mux"):
assert (features.check("webp_mux") or False) == features.check_module("webp")


def test_webp_anim() -> None:
with pytest.warns(DeprecationWarning, match="webp_anim"):
assert (features.check("webp_anim") or False) == features.check_module("webp")


@skip_unless_feature("libjpeg_turbo")
def test_libjpeg_turbo_version() -> None:
version = features.version("libjpeg_turbo")
Expand Down
12 changes: 1 addition & 11 deletions Tests/test_file_icns.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,11 @@ def test_sizes() -> None:
with Image.open(TEST_FILE) as im:
assert isinstance(im, IcnsImagePlugin.IcnsImageFile)
for w, h, r in im.info["sizes"]:
wr = w * r
hr = h * r
with pytest.warns(
DeprecationWarning, match=r"Setting size to \(width, height, scale\)"
):
im.size = (w, h, r)
im.load()
assert im.mode == "RGBA"
assert im.size == (wr, hr)

# Test using load() with scale
im.size = (w, h)
im.load(scale=r)
assert im.mode == "RGBA"
assert im.size == (wr, hr)
assert im.size == (w * r, h * r)

# Check that we cannot load an incorrect size
with pytest.raises(ValueError):
Expand Down
37 changes: 1 addition & 36 deletions Tests/test_file_iptc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from __future__ import annotations

import sys
from io import BytesIO, StringIO

import pytest
from io import BytesIO

from PIL import Image, IptcImagePlugin, TiffImagePlugin, TiffTags

Expand Down Expand Up @@ -101,35 +98,3 @@ def test_getiptcinfo_tiff_none() -> None:

# Assert
assert iptc is None


def test_i() -> None:
# Arrange
c = b"a"

# Act
with pytest.warns(DeprecationWarning, match="IptcImagePlugin.i"):
ret = IptcImagePlugin.i(c)

# Assert
assert ret == 97


def test_dump(monkeypatch: pytest.MonkeyPatch) -> None:
# Arrange
c = b"abc"
# Temporarily redirect stdout
mystdout = StringIO()
monkeypatch.setattr(sys, "stdout", mystdout)

# Act
with pytest.warns(DeprecationWarning, match="IptcImagePlugin.dump"):
IptcImagePlugin.dump(c)

# Assert
assert mystdout.getvalue() == "61 62 63 \n"


def test_pad_deprecation() -> None:
with pytest.warns(DeprecationWarning, match="IptcImagePlugin.PAD"):
assert IptcImagePlugin.PAD == b"\0\0\0\0"
8 changes: 0 additions & 8 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,14 +1115,6 @@ def test_repr_jpeg_error_returns_none(self) -> None:

assert im._repr_jpeg_() is None

def test_deprecation(self) -> None:
with Image.open(TEST_FILE) as im:
assert isinstance(im, JpegImagePlugin.JpegImageFile)
with pytest.warns(DeprecationWarning, match="huffman_ac"):
assert im.huffman_ac == {}
with pytest.warns(DeprecationWarning, match="huffman_dc"):
assert im.huffman_dc == {}


@pytest.mark.skipif(not is_win32(), reason="Windows only")
@skip_unless_feature("jpg")
Expand Down
31 changes: 3 additions & 28 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,7 @@ def test_additional_metadata(

im.save(out, tiffinfo=new_ifd)

@pytest.mark.parametrize(
"libtiff",
(
pytest.param(
True,
marks=pytest.mark.skipif(
not getattr(Image.core, "libtiff_support_custom_tags", False),
reason="Custom tags not supported by older libtiff",
),
),
False,
),
)
@pytest.mark.parametrize("libtiff", (True, False))
def test_custom_metadata(
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path, libtiff: bool
) -> None:
Expand Down Expand Up @@ -724,8 +712,7 @@ def test_exif_ifd(self) -> None:

with Image.open(out) as reloaded:
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
if Image.core.libtiff_support_custom_tags:
assert reloaded.tag_v2[34665] == 125456
assert reloaded.tag_v2[34665] == 125456

def test_crashing_metadata(
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
Expand Down Expand Up @@ -777,19 +764,7 @@ def test_read_icc(self, monkeypatch: pytest.MonkeyPatch) -> None:
assert icc_libtiff is not None
assert icc == icc_libtiff

@pytest.mark.parametrize(
"libtiff",
(
pytest.param(
True,
marks=pytest.mark.skipif(
not getattr(Image.core, "libtiff_support_custom_tags", False),
reason="Custom tags not supported by older libtiff",
),
),
False,
),
)
@pytest.mark.parametrize("libtiff", (True, False))
def test_write_icc(
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path, libtiff: bool
) -> None:
Expand Down
36 changes: 8 additions & 28 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
assert_image_similar_tofile,
assert_not_all_same,
hopper,
is_big_endian,
is_win32,
mark_if_feature_version,
skip_unless_feature,
Expand All @@ -50,19 +49,10 @@
PrettyPrinter = None


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


class TestImage:
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
@pytest.mark.parametrize("mode", Image.MODES)
def test_image_modes_success(self, mode: str) -> None:
helper_image_new(mode, (1, 1))
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 @@ -1142,39 +1132,29 @@ def test_close_graceful(self, caplog: pytest.LogCaptureFixture) -> None:
assert len(caplog.records) == 0
assert im.fp is None

def test_deprecation(self) -> None:
with pytest.warns(DeprecationWarning, match="Image.isImageType"):
assert not Image.isImageType(None)


class TestImageBytes:
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
@pytest.mark.parametrize("mode", Image.MODES)
def test_roundtrip_bytes_constructor(self, mode: str) -> None:
im = hopper(mode)
source_bytes = im.tobytes()

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

@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
@pytest.mark.parametrize("mode", Image.MODES)
def test_roundtrip_bytes_method(self, mode: str) -> None:
im = hopper(mode)
source_bytes = im.tobytes()

reloaded = helper_image_new(mode, im.size)
reloaded = Image.new(mode, im.size)
reloaded.frombytes(source_bytes)
assert reloaded.tobytes() == source_bytes

@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
@pytest.mark.parametrize("mode", Image.MODES)
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)
reloaded = helper_image_new(mode, im.size)
reloaded = Image.new(mode, im.size)
reloaded.putdata(im.getdata())
assert_image_equal(im, reloaded)

Expand Down
16 changes: 1 addition & 15 deletions Tests/test_image_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ def color(mode: str) -> int | tuple[int, ...]:
bands = Image.getmodebands(mode)
if bands == 1:
return 1
if mode in ("BGR;15", "BGR;16"):
# These modes have less than 8 bits per band,
# so (1, 2, 3) cannot be roundtripped.
return (16, 32, 49)
return tuple(range(1, bands + 1))

def check(self, mode: str, expected_color_int: int | None = None) -> None:
Expand Down Expand Up @@ -191,11 +187,6 @@ def check(self, mode: str, expected_color_int: int | None = None) -> None:
def test_basic(self, mode: str) -> None:
self.check(mode)

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

def test_list(self) -> None:
im = hopper()
assert im.getpixel([0, 0]) == (20, 20, 70)
Expand All @@ -218,7 +209,7 @@ def test_p_putpixel_rgb_rgba(self, mode: str, color: tuple[int, ...]) -> None:


class TestImagePutPixelError:
IMAGE_MODES1 = ["LA", "RGB", "RGBA", "BGR;15"]
IMAGE_MODES1 = ["LA", "RGB", "RGBA"]
IMAGE_MODES2 = ["L", "I", "I;16"]
INVALID_TYPES = ["foo", 1.0, None]

Expand All @@ -234,11 +225,6 @@ def test_putpixel_type_error1(self, mode: str) -> None:
(
("L", (0, 2), "color must be int or single-element tuple"),
("LA", (0, 3), "color must be int, or tuple of one or two elements"),
(
"BGR;15",
(0, 2),
"color must be int, or tuple of one or three elements",
),
(
"RGB",
(0, 2, 5),
Expand Down
9 changes: 0 additions & 9 deletions Tests/test_image_getim.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import pytest

from .helper import hopper


Expand All @@ -10,10 +8,3 @@ def test_sanity() -> None:

type_repr = repr(type(im.getim()))
assert "PyCapsule" in type_repr

with pytest.warns(DeprecationWarning, match="id property"):
assert isinstance(im.im.id, int)

with pytest.warns(DeprecationWarning, match="unsafe_ptrs property"):
ptrs = dict(im.im.unsafe_ptrs)
assert ptrs.keys() == {"image8", "image32", "image"}
10 changes: 0 additions & 10 deletions Tests/test_image_putdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ def test_mode_F() -> None:
assert list(im.getdata()) == target


@pytest.mark.parametrize("mode", ("BGR;15", "BGR;16", "BGR;24"))
def test_mode_BGR(mode: str) -> None:
data = [(16, 32, 49), (32, 32, 98)]
with pytest.warns(DeprecationWarning, match=mode):
im = Image.new(mode, (1, 2))
im.putdata(data)

assert list(im.getdata()) == data


def test_array_B() -> None:
# shouldn't segfault
# see https://github.com/python-pillow/Pillow/issues/1008
Expand Down
Loading
Loading