Pillow

Форк
0
/
test_deprecate.py 
93 строки · 2.6 Кб
1
from __future__ import annotations
2

3
import pytest
4

5
from PIL import _deprecate
6

7

8
@pytest.mark.parametrize(
9
    "version, expected",
10
    [
11
        (
12
            12,
13
            "Old thing is deprecated and will be removed in Pillow 12 "
14
            r"\(2025-10-15\)\. Use new thing instead\.",
15
        ),
16
        (
17
            None,
18
            r"Old thing is deprecated and will be removed in a future version\. "
19
            r"Use new thing instead\.",
20
        ),
21
    ],
22
)
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")
26

27

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")
32

33

34
@pytest.mark.parametrize(
35
    "deprecated, plural, expected",
36
    [
37
        (
38
            "Old thing",
39
            False,
40
            r"Old thing is deprecated and should be removed\.",
41
        ),
42
        (
43
            "Old things",
44
            True,
45
            r"Old things are deprecated and should be removed\.",
46
        ),
47
    ],
48
)
49
def test_old_version(deprecated: str, plural: bool, expected: str) -> None:
50
    expected = r""
51
    with pytest.raises(RuntimeError, match=expected):
52
        _deprecate.deprecate(deprecated, 1, plural=plural)
53

54

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

63

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

71

72
@pytest.mark.parametrize(
73
    "action",
74
    [
75
        "Upgrade to new thing",
76
        "Upgrade to new thing.",
77
    ],
78
)
79
def test_action(action: str) -> None:
80
    expected = (
81
        r"Old thing is deprecated and will be removed in Pillow 12 \(2025-10-15\)\. "
82
        r"Upgrade to new thing\."
83
    )
84
    with pytest.warns(DeprecationWarning, match=expected):
85
        _deprecate.deprecate("Old thing", 12, action=action)
86

87

88
def test_no_replacement_or_action() -> None:
89
    expected = (
90
        r"Old thing is deprecated and will be removed in Pillow 12 \(2025-10-15\)"
91
    )
92
    with pytest.warns(DeprecationWarning, match=expected):
93
        _deprecate.deprecate("Old thing", 12)
94

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.