File: test_cache.py

package info (click to toggle)
yarl 1.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,060 kB
  • sloc: python: 6,594; makefile: 212
file content (101 lines) | stat: -rw-r--r-- 3,007 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import pytest

import yarl

# Don't check the actual behavior but make sure that calls are allowed


def teardown_module() -> None:
    yarl.cache_configure()


def test_cache_clear() -> None:
    yarl.cache_clear()


def test_cache_info() -> None:
    info = yarl.cache_info()
    assert info.keys() == {
        "idna_encode",
        "idna_decode",
        "ip_address",
        "host_validate",
        "encode_host",
    }


def test_cache_configure_default() -> None:
    yarl.cache_configure()


def test_cache_configure_None() -> None:
    yarl.cache_configure(
        idna_decode_size=None,
        idna_encode_size=None,
        encode_host_size=None,
    )


def test_cache_configure_None_including_deprecated() -> None:
    msg = (
        r"cache_configure\(\) no longer accepts the ip_address_size "
        r"or host_validate_size arguments, they are used to set the "
        r"encode_host_size instead and will be removed in the future"
    )
    with pytest.warns(DeprecationWarning, match=msg):
        yarl.cache_configure(
            idna_decode_size=None,
            idna_encode_size=None,
            encode_host_size=None,
            ip_address_size=None,
            host_validate_size=None,
        )
    assert yarl.cache_info()["idna_decode"].maxsize is None
    assert yarl.cache_info()["idna_encode"].maxsize is None
    assert yarl.cache_info()["encode_host"].maxsize is None


def test_cache_configure_None_only_deprecated() -> None:
    msg = (
        r"cache_configure\(\) no longer accepts the ip_address_size "
        r"or host_validate_size arguments, they are used to set the "
        r"encode_host_size instead and will be removed in the future"
    )
    with pytest.warns(DeprecationWarning, match=msg):
        yarl.cache_configure(
            ip_address_size=None,
            host_validate_size=None,
        )
    assert yarl.cache_info()["encode_host"].maxsize is None


def test_cache_configure_explicit() -> None:
    yarl.cache_configure(
        idna_decode_size=128,
        idna_encode_size=128,
        encode_host_size=128,
    )
    assert yarl.cache_info()["idna_decode"].maxsize == 128
    assert yarl.cache_info()["idna_encode"].maxsize == 128
    assert yarl.cache_info()["encode_host"].maxsize == 128


def test_cache_configure_waring() -> None:
    msg = (
        r"cache_configure\(\) no longer accepts the ip_address_size "
        r"or host_validate_size arguments, they are used to set the "
        r"encode_host_size instead and will be removed in the future"
    )
    with pytest.warns(DeprecationWarning, match=msg):
        yarl.cache_configure(
            idna_encode_size=1024,
            idna_decode_size=1024,
            ip_address_size=1024,
            host_validate_size=1024,
        )

    assert yarl.cache_info()["encode_host"].maxsize == 1024
    with pytest.warns(DeprecationWarning, match=msg):
        yarl.cache_configure(host_validate_size=None)

    assert yarl.cache_info()["encode_host"].maxsize is None