|
@@ -34,26 +34,47 @@ def test_call_event_handler():
|
|
|
def test_fn():
|
|
|
pass
|
|
|
|
|
|
+ test_fn.__qualname__ = "test_fn"
|
|
|
+
|
|
|
def test_fn_with_args(_, arg1, arg2):
|
|
|
pass
|
|
|
|
|
|
+ test_fn_with_args.__qualname__ = "test_fn_with_args"
|
|
|
+
|
|
|
handler = EventHandler(fn=test_fn)
|
|
|
event_spec = handler()
|
|
|
|
|
|
assert event_spec.handler == handler
|
|
|
assert event_spec.local_args == ()
|
|
|
assert event_spec.args == ()
|
|
|
+ assert format.format_event(event_spec) == 'E("test_fn", {})'
|
|
|
|
|
|
handler = EventHandler(fn=test_fn_with_args)
|
|
|
event_spec = handler(make_var("first"), make_var("second"))
|
|
|
|
|
|
+ # Test passing vars as args.
|
|
|
assert event_spec.handler == handler
|
|
|
assert event_spec.local_args == ()
|
|
|
assert event_spec.args == (("arg1", "first"), ("arg2", "second"))
|
|
|
+ assert (
|
|
|
+ format.format_event(event_spec)
|
|
|
+ == 'E("test_fn_with_args", {arg1:first,arg2:second})'
|
|
|
+ )
|
|
|
+
|
|
|
+ # Passing args as strings should format differently.
|
|
|
+ event_spec = handler("first", "second") # type: ignore
|
|
|
+ assert (
|
|
|
+ format.format_event(event_spec)
|
|
|
+ == 'E("test_fn_with_args", {arg1:"first",arg2:"second"})'
|
|
|
+ )
|
|
|
|
|
|
first, second = 123, "456"
|
|
|
handler = EventHandler(fn=test_fn_with_args)
|
|
|
event_spec = handler(first, second) # type: ignore
|
|
|
+ assert (
|
|
|
+ format.format_event(event_spec)
|
|
|
+ == 'E("test_fn_with_args", {arg1:123,arg2:"456"})'
|
|
|
+ )
|
|
|
|
|
|
assert event_spec.handler == handler
|
|
|
assert event_spec.local_args == ()
|