import accordian
import pytest


def test_unknown_event(loop):
    """
    An exception should be thrown when trying to register a
    handler for an unknown event.
    """
    dispatch = accordian.Dispatch(loop=loop)
    with pytest.raises(ValueError):
        dispatch.on("unknown")


def test_clean_stop(loop):
    dispatch = accordian.Dispatch(loop=loop)
    loop.run_until_complete(dispatch.start())
    loop.run_until_complete(dispatch.stop())

@@ -4,31 +4,682 @@
 ort 
-accordian%0Aimport pytest
+pytest%0A%0A%0Adef test_start_idempotent(loop, dispatch):%0A    loop.run_until_complete(dispatch.start())%0A    assert dispatch.running%0A%0A    loop.run_until_complete(dispatch.start())%0A    assert dispatch.running%0A%0A%0Adef test_stop_idempotent(loop, dispatch):%0A    loop.run_until_complete(dispatch.start())%0A    assert dispatch.running%0A%0A    loop.run_until_complete(dispatch.stop())%0A    assert not dispatch.running%0A%0A    loop.run_until_complete(dispatch.stop())%0A    assert not dispatch.running%0A%0A%0Adef test_clean_stop(loop, dispatch):%0A    %22%22%22 Stop ensures the main dispatch loop shuts down gracefully %22%22%22%0A    loop.run_until_complete(dispatch.start())%0A    loop.run_until_complete(dispatch.stop())
 %0A%0A%0Ad
@@ -700,20 +700,24 @@
 n_event(
-loop
+dispatch
 ):%0A    %22
@@ -825,53 +825,8 @@
 %22%22%22%0A
-    dispatch = accordian.Dispatch(loop=loop)%0A
     
@@ -903,158 +903,1505 @@
 est_
-clean_stop(loop):%0A    dispatch = accordian.Dispatch(loop=loop)%0A    loop.run_until_complete(dispatch.start())%0A    loop.run_until_complete(dispatch.stop())
+register(dispatch):%0A    event = %22my-event%22%0A    params = %5B%22x%22, %22y%22, %22z%22%5D%0A    dispatch.register(event, params)%0A    assert %22my-event%22 in dispatch._handlers%0A%0A%0Adef test_register_twice(dispatch):%0A    event = %22my-event%22%0A    params = %5B%22x%22, %22y%22, %22z%22%5D%0A    dispatch.register(event, params)%0A%0A    with pytest.raises(ValueError):%0A        dispatch.register(event, params)%0A%0A%0Adef test_register_running(dispatch, loop):%0A    event = %22my-event%22%0A    params = %5B%22x%22, %22y%22, %22z%22%5D%0A    loop.run_until_complete(dispatch.start())%0A%0A    with pytest.raises(RuntimeError):%0A        dispatch.register(event, params)%0A    loop.run_until_complete(dispatch.stop())%0A%0A%0Adef test_unregister_unknown(dispatch):%0A    assert %22unknown-event%22 not in dispatch._handlers%0A    dispatch.unregister(%22unknown-event%22)%0A%0A%0Adef test_unregister_running(dispatch, loop):%0A    event = %22my-event%22%0A    params = %5B%22x%22, %22y%22, %22z%22%5D%0A    dispatch.register(event, params)%0A%0A    loop.run_until_complete(dispatch.start())%0A    with pytest.raises(RuntimeError):%0A        dispatch.unregister(event)%0A    loop.run_until_complete(dispatch.stop())%0A%0A%0Adef test_single_handler(dispatch, loop):%0A    event = %22my-event%22%0A    params = %7B%22x%22: 4, %22y%22: 5, %22z%22: 6%7D%0A    dispatch.register(event, params.keys())%0A%0A    called = False%0A%0A    @dispatch.on(event)%0A    async def handle(x, y):%0A        nonlocal called%0A        called = True%0A%0A    for task in %5B%0A        dispatch.start(),%0A        dispatch.trigger(event, params),%0A        dispatch.stop()%0A    %5D:%0A        loop.run_until_complete(task)%0A    assert called
 %0A

Test dispatch (un)register, basic handler