MCPcopy Create free account
hub / github.com/dot-agent/nextpy / test_computed_var_cached

Function test_computed_var_cached

tests/test_state.py:1079–1102  ·  view source on GitHub ↗

Test that a ComputedVar doesn't recalculate when accessed.

()

Source from the content-addressed store, hash-verified

1077
1078
1079def test_computed_var_cached():
1080 """Test that a ComputedVar doesn't recalculate when accessed."""
1081 comp_v_calls = 0
1082
1083 class ComputedState(BaseState):
1084 v: int = 0
1085
1086 @xt.cached_var
1087 def comp_v(self) -> int:
1088 nonlocal comp_v_calls
1089 comp_v_calls += 1
1090 return self.v
1091
1092 cs = ComputedState()
1093 assert cs.dict()[cs.get_full_name()]["v"] == 0
1094 assert comp_v_calls == 1
1095 assert cs.dict()[cs.get_full_name()]["comp_v"] == 0
1096 assert comp_v_calls == 1
1097 assert cs.comp_v == 0
1098 assert comp_v_calls == 1
1099 cs.v = 1
1100 assert comp_v_calls == 1
1101 assert cs.comp_v == 1
1102 assert comp_v_calls == 2
1103
1104
1105def test_computed_var_cached_depends_on_non_cached():

Callers

nothing calls this directly

Calls 3

ComputedStateClass · 0.85
get_full_nameMethod · 0.80
dictMethod · 0.45

Tested by

no test coverage detected