async def test_custom_connect_and_send(handler): """Tests using the custom connect and send implementations.""" # Arrange test_signal = "PREFIX_TEST" stored_target = None def connect(signal, target): assert signal == test_signal nonlocal stored_target stored_target = target def disconnect(): nonlocal stored_target stored_target = None return disconnect def send(signal, *args): assert signal == test_signal stored_target(*args) # pylint:disable=not-callable dispatcher = Dispatcher(connect=connect, send=send, signal_prefix="PREFIX_") # Act dispatcher.connect("TEST", handler) dispatcher.send("TEST") # Assert assert handler.fired
async def test_send_async_handler(async_handler): """Tests sending to async handlers.""" # Arrange dispatcher = Dispatcher() dispatcher.connect("TEST", async_handler) # Act await asyncio.gather(*dispatcher.send("TEST")) # Assert assert async_handler.fired
async def test_send_async_partial_handler(async_handler): """Tests sending to async handlers.""" # Arrange partial = functools.partial(async_handler) dispatcher = Dispatcher() dispatcher.connect("TEST", partial) # Act await asyncio.gather(*dispatcher.send("TEST")) # Assert assert async_handler.fired
async def test_send(handler): """Tests sending to async handlers.""" # Arrange dispatcher = Dispatcher() dispatcher.connect("TEST", handler) args = object() # Act await asyncio.gather(*dispatcher.send("TEST", args)) # Assert assert handler.fired assert handler.args[0] == args