-
-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathtest_compat.py
More file actions
65 lines (46 loc) · 1.62 KB
/
Copy pathtest_compat.py
File metadata and controls
65 lines (46 loc) · 1.62 KB
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
# SPDX-License-Identifier: MIT
import types
from typing import Protocol
import pytest
import attr
@pytest.fixture(name="mp")
def _mp():
return types.MappingProxyType({"x": 42, "y": "foo"})
class TestMetadataProxy:
"""
Ensure properties of metadata proxy independently of hypothesis strategies.
"""
def test_repr(self, mp):
"""
repr makes sense and is consistent across Python versions.
"""
assert any(
[
"mappingproxy({'x': 42, 'y': 'foo'})" == repr(mp),
"mappingproxy({'y': 'foo', 'x': 42})" == repr(mp),
]
)
def test_immutable(self, mp):
"""
All mutating methods raise errors.
"""
with pytest.raises(TypeError, match="not support item assignment"):
mp["z"] = 23
with pytest.raises(TypeError, match="not support item deletion"):
del mp["x"]
with pytest.raises(AttributeError, match="no attribute 'update'"):
mp.update({})
with pytest.raises(AttributeError, match="no attribute 'clear'"):
mp.clear()
with pytest.raises(AttributeError, match="no attribute 'pop'"):
mp.pop("x")
with pytest.raises(AttributeError, match="no attribute 'popitem'"):
mp.popitem()
with pytest.raises(AttributeError, match="no attribute 'setdefault'"):
mp.setdefault("x")
def test_attrsinstance_subclass_protocol():
"""
It's possible to subclass AttrsInstance and Protocol at once.
"""
class Foo(attr.AttrsInstance, Protocol):
def attribute(self) -> int: ...