1
from __future__ import annotations
5
from PIL import _deprecate
8
@pytest.mark.parametrize(
13
"Old thing is deprecated and will be removed in Pillow 12 "
14
r"\(2025-10-15\)\. Use new thing instead\.",
18
r"Old thing is deprecated and will be removed in a future version\. "
19
r"Use new thing instead\.",
23
def test_version(version: int | None, expected: str) -> None:
24
with pytest.warns(DeprecationWarning, match=expected):
25
_deprecate.deprecate("Old thing", version, "new thing")
28
def test_unknown_version() -> None:
29
expected = r"Unknown removal version: 12345. Update PIL\._deprecate\?"
30
with pytest.raises(ValueError, match=expected):
31
_deprecate.deprecate("Old thing", 12345, "new thing")
34
@pytest.mark.parametrize(
35
"deprecated, plural, expected",
40
r"Old thing is deprecated and should be removed\.",
45
r"Old things are deprecated and should be removed\.",
49
def test_old_version(deprecated: str, plural: bool, expected: str) -> None:
51
with pytest.raises(RuntimeError, match=expected):
52
_deprecate.deprecate(deprecated, 1, plural=plural)
55
def test_plural() -> None:
57
r"Old things are deprecated and will be removed in Pillow 12 \(2025-10-15\)\. "
58
r"Use new thing instead\."
60
with pytest.warns(DeprecationWarning, match=expected):
61
_deprecate.deprecate("Old things", 12, "new thing", plural=True)
64
def test_replacement_and_action() -> None:
65
expected = "Use only one of 'replacement' and 'action'"
66
with pytest.raises(ValueError, match=expected):
68
"Old thing", 12, replacement="new thing", action="Upgrade to new thing"
72
@pytest.mark.parametrize(
75
"Upgrade to new thing",
76
"Upgrade to new thing.",
79
def test_action(action: str) -> None:
81
r"Old thing is deprecated and will be removed in Pillow 12 \(2025-10-15\)\. "
82
r"Upgrade to new thing\."
84
with pytest.warns(DeprecationWarning, match=expected):
85
_deprecate.deprecate("Old thing", 12, action=action)
88
def test_no_replacement_or_action() -> None:
90
r"Old thing is deprecated and will be removed in Pillow 12 \(2025-10-15\)"
92
with pytest.warns(DeprecationWarning, match=expected):
93
_deprecate.deprecate("Old thing", 12)