test_cached_property.py 472 B

123456789101112131415161718192021222324252627282930
  1. import pytest
  2. from yarl._url import cached_property
  3. class A:
  4. def __init__(self):
  5. self._cache = {}
  6. @cached_property
  7. def prop(self):
  8. """Docstring."""
  9. return 1
  10. def test_reify():
  11. a = A()
  12. assert 1 == a.prop
  13. def test_reify_class():
  14. assert isinstance(A.prop, cached_property)
  15. assert "Docstring." == A.prop.__doc__
  16. def test_reify_assignment():
  17. a = A()
  18. with pytest.raises(AttributeError):
  19. a.prop = 123