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

Function test_process_event_substate

tests/units/test_state.py:961–1009  ·  view source on GitHub ↗

Test processing an event on a substate. Args: token: A token. mock_base_state_event_processor: The event processor. emitted_deltas: List to capture emitted deltas.

(
    token: str,
    mock_base_state_event_processor: BaseStateEventProcessor,
    emitted_deltas: list,
)

Source from the content-addressed store, hash-verified

959
960@pytest.mark.asyncio
961async def test_process_event_substate(
962 token: str,
963 mock_base_state_event_processor: BaseStateEventProcessor,
964 emitted_deltas: list,
965):
966 """Test processing an event on a substate.
967
968 Args:
969 token: A token.
970 mock_base_state_event_processor: The event processor.
971 emitted_deltas: List to capture emitted deltas.
972 """
973 # Events should bubble down to the substate.
974 event = Event(
975 name=f"{ChildState.get_full_name()}.change_both",
976 payload={"value": "hi", "count": 12},
977 )
978 async with mock_base_state_event_processor as processor:
979 await processor.enqueue(token, event)
980 assert emitted_deltas == [
981 (
982 token,
983 {
984 ChildState.get_full_name(): {
985 "value" + FIELD_MARKER: "HI",
986 "count" + FIELD_MARKER: 24,
987 },
988 GrandchildState3.get_full_name(): {"computed" + FIELD_MARKER: ""},
989 },
990 )
991 ]
992 emitted_deltas.clear()
993
994 # Test with the grandchild state.
995 event = Event(
996 name=f"{GrandchildState.get_full_name()}.set_value2",
997 payload={"value": "new"},
998 )
999 async with mock_base_state_event_processor as processor:
1000 await processor.enqueue(token, event)
1001 assert emitted_deltas == [
1002 (
1003 token,
1004 {
1005 GrandchildState.get_full_name(): {"value2" + FIELD_MARKER: "new"},
1006 GrandchildState3.get_full_name(): {"computed" + FIELD_MARKER: ""},
1007 },
1008 )
1009 ]
1010
1011
1012@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 4

EventClass · 0.90
get_full_nameMethod · 0.80
clearMethod · 0.80
enqueueMethod · 0.45

Tested by

no test coverage detected