MCPcopy
hub / github.com/reflex-dev/reflex / test_deserialize_gc_state_disk

Function test_deserialize_gc_state_disk

tests/units/test_state.py:4304–4337  ·  view source on GitHub ↗

Test that a state can be deserialized from disk with a grandchild state. Args: token: A token.

(token)

Source from the content-addressed store, hash-verified

4302
4303@pytest.mark.asyncio
4304async def test_deserialize_gc_state_disk(token):
4305 """Test that a state can be deserialized from disk with a grandchild state.
4306
4307 Args:
4308 token: A token.
4309 """
4310
4311 class Root(BaseState):
4312 pass
4313
4314 class State(Root):
4315 num: int = 42
4316
4317 class Child(State):
4318 foo: str = "bar"
4319
4320 bs_token = BaseStateToken(ident=token, cls=Root)
4321
4322 dsm = StateManagerDisk()
4323 async with dsm.modify_state(bs_token) as root:
4324 s = await root.get_state(State)
4325 s.num += 1
4326 c = await root.get_state(Child)
4327 assert s._get_was_touched()
4328 assert not c._get_was_touched()
4329 await dsm.close()
4330
4331 dsm2 = StateManagerDisk()
4332 root = await dsm2.get_state(bs_token)
4333 s = await root.get_state(State)
4334 assert s.num == 43
4335 c = await root.get_state(Child)
4336 assert c.foo == "bar"
4337 await dsm2.close()
4338
4339
4340class Obj(Base):

Callers

nothing calls this directly

Calls 7

modify_stateMethod · 0.95
closeMethod · 0.95
get_stateMethod · 0.95
BaseStateTokenClass · 0.90
StateManagerDiskClass · 0.90
_get_was_touchedMethod · 0.80
get_stateMethod · 0.45

Tested by

no test coverage detected