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
|
from typing import Type
import pytest
from multidict import MultiMapping
from multidict._compat import USE_EXTENSIONS
from multidict._multidict_py import CIMultiDict as _CIMultiDict
from multidict._multidict_py import MultiDict as _MultiDict # noqa: E402
from multidict._multidict_py import getversion as _getversion
if USE_EXTENSIONS:
from multidict._multidict import ( # type: ignore
CIMultiDict,
MultiDict,
getversion,
)
class VersionMixin:
cls: Type[MultiMapping[str]]
def getver(self, md):
raise NotImplementedError
def test_getversion_bad_param(self):
with pytest.raises(TypeError):
self.getver(1)
def test_ctor(self):
m1 = self.cls()
v1 = self.getver(m1)
m2 = self.cls()
v2 = self.getver(m2)
assert v1 != v2
def test_add(self):
m = self.cls()
v = self.getver(m)
m.add("key", "val")
assert self.getver(m) > v
def test_delitem(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
del m["key"]
assert self.getver(m) > v
def test_delitem_not_found(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
with pytest.raises(KeyError):
del m["notfound"]
assert self.getver(m) == v
def test_setitem(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m["key"] = "val2"
assert self.getver(m) > v
def test_setitem_not_found(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m["notfound"] = "val2"
assert self.getver(m) > v
def test_clear(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m.clear()
assert self.getver(m) > v
def test_setdefault(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m.setdefault("key2", "val2")
assert self.getver(m) > v
def test_popone(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m.popone("key")
assert self.getver(m) > v
def test_popone_default(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m.popone("key2", "default")
assert self.getver(m) == v
def test_popone_key_error(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
with pytest.raises(KeyError):
m.popone("key2")
assert self.getver(m) == v
def test_pop(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m.pop("key")
assert self.getver(m) > v
def test_pop_default(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m.pop("key2", "default")
assert self.getver(m) == v
def test_pop_key_error(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
with pytest.raises(KeyError):
m.pop("key2")
assert self.getver(m) == v
def test_popall(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m.popall("key")
assert self.getver(m) > v
def test_popall_default(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m.popall("key2", "default")
assert self.getver(m) == v
def test_popall_key_error(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
with pytest.raises(KeyError):
m.popall("key2")
assert self.getver(m) == v
def test_popitem(self):
m = self.cls()
m.add("key", "val")
v = self.getver(m)
m.popitem()
assert self.getver(m) > v
def test_popitem_key_error(self):
m = self.cls()
v = self.getver(m)
with pytest.raises(KeyError):
m.popitem()
assert self.getver(m) == v
if USE_EXTENSIONS:
class TestMultiDict(VersionMixin):
cls = MultiDict
def getver(self, md):
return getversion(md)
if USE_EXTENSIONS:
class TestCIMultiDict(VersionMixin):
cls = CIMultiDict
def getver(self, md):
return getversion(md)
class TestPyMultiDict(VersionMixin):
cls = _MultiDict # type: ignore[assignment]
def getver(self, md):
return _getversion(md)
class TestPyCIMultiDict(VersionMixin):
cls = _CIMultiDict # type: ignore[assignment]
def getver(self, md):
return _getversion(md)
|