File size: 5,972 Bytes
065fee7 |
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
from typing import Callable, Type
import pytest
from multidict import MultiMapping
def test_getversion_bad_param(multidict_getversion_callable):
with pytest.raises(TypeError):
multidict_getversion_callable(1)
def test_ctor(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m1 = any_multidict_class()
v1 = multidict_getversion_callable(m1)
m2 = any_multidict_class()
v2 = multidict_getversion_callable(m2)
assert v1 != v2
def test_add(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
v = multidict_getversion_callable(m)
m.add("key", "val")
assert multidict_getversion_callable(m) > v
def test_delitem(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
del m["key"]
assert multidict_getversion_callable(m) > v
def test_delitem_not_found(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
with pytest.raises(KeyError):
del m["notfound"]
assert multidict_getversion_callable(m) == v
def test_setitem(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m["key"] = "val2"
assert multidict_getversion_callable(m) > v
def test_setitem_not_found(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m["notfound"] = "val2"
assert multidict_getversion_callable(m) > v
def test_clear(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m.clear()
assert multidict_getversion_callable(m) > v
def test_setdefault(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m.setdefault("key2", "val2")
assert multidict_getversion_callable(m) > v
def test_popone(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m.popone("key")
assert multidict_getversion_callable(m) > v
def test_popone_default(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m.popone("key2", "default")
assert multidict_getversion_callable(m) == v
def test_popone_key_error(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
with pytest.raises(KeyError):
m.popone("key2")
assert multidict_getversion_callable(m) == v
def test_pop(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m.pop("key")
assert multidict_getversion_callable(m) > v
def test_pop_default(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m.pop("key2", "default")
assert multidict_getversion_callable(m) == v
def test_pop_key_error(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
with pytest.raises(KeyError):
m.pop("key2")
assert multidict_getversion_callable(m) == v
def test_popall(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m.popall("key")
assert multidict_getversion_callable(m) > v
def test_popall_default(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m.popall("key2", "default")
assert multidict_getversion_callable(m) == v
def test_popall_key_error(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
with pytest.raises(KeyError):
m.popall("key2")
assert multidict_getversion_callable(m) == v
def test_popitem(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
m.add("key", "val")
v = multidict_getversion_callable(m)
m.popitem()
assert multidict_getversion_callable(m) > v
def test_popitem_key_error(
any_multidict_class: Type[MultiMapping[str]],
multidict_getversion_callable: Callable,
) -> None:
m = any_multidict_class()
v = multidict_getversion_callable(m)
with pytest.raises(KeyError):
m.popitem()
assert multidict_getversion_callable(m) == v
|