Coverage for Users / vladimirpavlov / PycharmProjects / parameterizable / tests / test_cacheable_properties_mixin_get_all.py: 96%
52 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-01 16:37 -0600
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-01 16:37 -0600
1from functools import cached_property
2from mixinforge import CacheablePropertiesMixin
4class A(CacheablePropertiesMixin):
5 @cached_property
6 def x(self):
7 return 1
9 @cached_property
10 def y(self):
11 return 2
13 @property
14 def z(self):
15 return 3
17 def regular_method(self):
18 pass
20def test_get_cached_values_basic():
21 """Test that _get_cached_values() returns dict with cached property values."""
22 a = A()
23 # Cache properties
24 _ = a.x
25 _ = a.y
27 cached_values = a._get_all_cached_properties()
29 assert isinstance(cached_values, dict)
30 assert cached_values == {"x": 1, "y": 2}
32def test_get_cached_values_partial():
33 """Test that _get_cached_values() only includes actually cached properties."""
34 a = A()
35 # Cache only x, not y
36 _ = a.x
38 cached_values = a._get_all_cached_properties()
40 assert cached_values == {"x": 1}
41 assert "y" not in cached_values
43def test_get_cached_values_empty():
44 """Test that _get_cached_values() returns empty dict when nothing is cached."""
45 a = A()
47 cached_values = a._get_all_cached_properties()
49 assert cached_values == {}
51def test_get_cached_values_after_invalidation():
52 """Test that _get_cached_values() returns empty dict after invalidation."""
53 a = A()
54 _ = a.x
55 _ = a.y
57 a._invalidate_cache()
58 cached_values = a._get_all_cached_properties()
60 assert cached_values == {}
62def test_get_cached_values_inheritance():
63 """Test that _get_cached_values() works with inherited cached properties."""
64 class Base(CacheablePropertiesMixin):
65 @cached_property
66 def base_prop(self):
67 return "base"
69 class Child(Base):
70 @cached_property
71 def child_prop(self):
72 return "child"
74 c = Child()
75 _ = c.base_prop
76 _ = c.child_prop
78 cached_values = c._get_all_cached_properties()
80 assert cached_values == {"base_prop": "base", "child_prop": "child"}