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

Function test_event_var_data

tests/units/test_event.py:462–518  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

460
461
462def test_event_var_data():
463 class S(BaseState):
464 x: Field[int] = field(0)
465
466 @event
467 def s(self, value: int):
468 pass
469
470 @event
471 def s2(self):
472 pass
473
474 # Handler doesn't have any _var_data because it's just a str
475 handler_var = Var.create(S.s2)
476 assert handler_var._get_all_var_data() is None
477
478 # Ensure spec carries _var_data
479 spec_var = Var.create(S.s(S.x))
480 assert spec_var._get_all_var_data() == S.x._get_all_var_data()
481
482 # Needed to instantiate the EventChain
483 def _args_spec(value: Var[int]) -> tuple[Var[int]]:
484 return (value,)
485
486 # Ensure chain carries _var_data
487 chain_var = Var.create(
488 EventChain(
489 events=[S.s(S.x)],
490 args_spec=_args_spec,
491 invocation=rx.vars.FunctionStringVar.create(""),
492 )
493 )
494 assert chain_var._get_all_var_data() == S.x._get_all_var_data()
495
496 chain_var_data = Var.create(
497 EventChain(
498 events=[],
499 args_spec=_args_spec,
500 )
501 )._get_all_var_data()
502 assert chain_var_data is not None
503
504 # Imports include EVENTS (which now imports module-level ``addEvents``)
505 # and the state/event-loop providers ride along as app_wraps so the
506 # compiler can mount them in the app root. ``addEvents`` reaches its
507 # call sites through the import, not a hoisted hook, so ``hooks`` is
508 # empty here. Compare structurally — providers are fresh instances per
509 # call, so identity-based VarData equality wouldn't match.
510 assert dict(chain_var_data.imports) == {
511 k: tuple(v) for k, v in Imports.EVENTS.items()
512 }
513 assert chain_var_data.hooks == ()
514 assert sorted(p for p, _ in chain_var_data.app_wraps) == [90, 100]
515 assert {wrapper.tag for _, wrapper in chain_var_data.app_wraps} == {
516 "StateProvider",
517 "EventLoopProvider",
518 }
519

Callers

nothing calls this directly

Calls 5

EventChainFunction · 0.90
sMethod · 0.80
itemsMethod · 0.80
createMethod · 0.45
_get_all_var_dataMethod · 0.45

Tested by

no test coverage detected