mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Merge pull request #84 from radarhere/deprecations-helper
This commit is contained in:
commit
331595926c
|
@ -29,6 +29,27 @@ def test_unknown_version():
|
||||||
_deprecate.deprecate("Old thing", 12345, "new thing")
|
_deprecate.deprecate("Old thing", 12345, "new thing")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"deprecated, plural, expected",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"Old thing",
|
||||||
|
False,
|
||||||
|
r"Old thing is deprecated and should be removed\.",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"Old things",
|
||||||
|
True,
|
||||||
|
r"Old things are deprecated and should be removed\.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_old_version(deprecated, plural, expected):
|
||||||
|
expected = r""
|
||||||
|
with pytest.raises(RuntimeError, match=expected):
|
||||||
|
_deprecate.deprecate(deprecated, 1, plural=plural)
|
||||||
|
|
||||||
|
|
||||||
def test_plural():
|
def test_plural():
|
||||||
expected = (
|
expected = (
|
||||||
r"Old things are deprecated and will be removed in Pillow 10 \(2023-07-01\)\. "
|
r"Old things are deprecated and will be removed in Pillow 10 \(2023-07-01\)\. "
|
||||||
|
|
|
@ -2,6 +2,8 @@ from __future__ import annotations
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
from . import __version__
|
||||||
|
|
||||||
|
|
||||||
def deprecate(
|
def deprecate(
|
||||||
deprecated: str,
|
deprecated: str,
|
||||||
|
@ -38,10 +40,12 @@ def deprecate(
|
||||||
|
|
||||||
is_ = "are" if plural else "is"
|
is_ = "are" if plural else "is"
|
||||||
|
|
||||||
if when == 10:
|
if when is None:
|
||||||
removed = "Pillow 10 (2023-07-01)"
|
|
||||||
elif when is None:
|
|
||||||
removed = "a future version"
|
removed = "a future version"
|
||||||
|
elif when <= int(__version__.split(".")[0]):
|
||||||
|
raise RuntimeError(f"{deprecated} {is_} deprecated and should be removed.")
|
||||||
|
elif when == 10:
|
||||||
|
removed = "Pillow 10 (2023-07-01)"
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unknown removal version, update {__name__}?")
|
raise ValueError(f"Unknown removal version, update {__name__}?")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user