blob: 5dcb5ece2318cf1840d63c4541f428190b9c114b (
plain) (
blame)
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
|
import pytest
from yarl._url import cached_property
def test_reify():
class A:
def __init__(self):
self._cache = {}
@cached_property
def prop(self):
return 1
a = A()
assert 1 == a.prop
def test_reify_class():
class A:
def __init__(self):
self._cache = {}
@cached_property
def prop(self):
"""Docstring."""
return 1
assert isinstance(A.prop, cached_property)
assert "Docstring." == A.prop.__doc__
def test_reify_assignment():
class A:
def __init__(self):
self._cache = {}
@cached_property
def prop(self):
return 1
a = A()
with pytest.raises(AttributeError):
a.prop = 123
|