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
|
from collections.abc import Mapping, MutableMapping
import pytest
from multidict import MultiMapping, MutableMultiMapping
def test_abc_inheritance():
assert issubclass(MultiMapping, Mapping)
assert not issubclass(MultiMapping, MutableMapping)
assert issubclass(MutableMultiMapping, Mapping)
assert issubclass(MutableMultiMapping, MutableMapping)
class A(MultiMapping):
def __getitem__(self, key):
pass
def __iter__(self):
pass
def __len__(self):
pass
def getall(self, key, default=None):
super().getall(key, default)
def getone(self, key, default=None):
super().getone(key, default)
def test_abc_getall():
with pytest.raises(KeyError):
A().getall("key")
def test_abc_getone():
with pytest.raises(KeyError):
A().getone("key")
class B(A, MutableMultiMapping):
def __setitem__(self, key, value):
pass
def __delitem__(self, key):
pass
def add(self, key, value):
super().add(key, value)
def extend(self, *args, **kwargs):
super().extend(*args, **kwargs)
def popall(self, key, default=None):
super().popall(key, default)
def popone(self, key, default=None):
super().popone(key, default)
def test_abc_add():
with pytest.raises(NotImplementedError):
B().add("key", "val")
def test_abc_extend():
with pytest.raises(NotImplementedError):
B().extend()
def test_abc_popone():
with pytest.raises(KeyError):
B().popone("key")
def test_abc_popall():
with pytest.raises(KeyError):
B().popall("key")
def test_multidict_inheritance(any_multidict_class):
assert issubclass(any_multidict_class, MultiMapping)
assert issubclass(any_multidict_class, MutableMultiMapping)
def test_proxy_inheritance(any_multidict_proxy_class):
assert issubclass(any_multidict_proxy_class, MultiMapping)
assert not issubclass(any_multidict_proxy_class, MutableMultiMapping)
def test_generic_type_in_runtime():
MultiMapping[str]
MutableMultiMapping[str]
|