1
0

test_event.py 953 B

1234567891011121314151617181920212223242526272829303132333435
  1. import pytest
  2. from pynecone.event import Event, EventHandler, EventSpec
  3. def test_create_event():
  4. """Test creating an event."""
  5. event = Event(token="token", name="state.do_thing", payload={"arg": "value"})
  6. assert event.token == "token"
  7. assert event.name == "state.do_thing"
  8. assert event.payload == {"arg": "value"}
  9. def test_call_event_handler():
  10. """Test that calling an event handler creates an event spec."""
  11. def test_fn():
  12. pass
  13. def test_fn_with_args(_, arg1, arg2):
  14. pass
  15. handler = EventHandler(fn=test_fn)
  16. event_spec = handler()
  17. assert event_spec.handler == handler
  18. assert event_spec.local_args == ()
  19. assert event_spec.args == ()
  20. handler = EventHandler(fn=test_fn_with_args)
  21. event_spec = handler("first", "second")
  22. assert event_spec.handler == handler
  23. assert event_spec.local_args == ()
  24. assert event_spec.args == (("arg1", "first"), ("arg2", "second"))