def test_signal_dispatch_with_correct_arguments(): test_signal = Signal(arguments=['number']) test_signal.connect( sender=Sender, receiver=coroutine_receiver_double_multiplier) task = test_signal.dispatch(sender=Sender, number=2)[0] loop = asyncio.get_event_loop() result = loop.run_until_complete(task) assert result == 4 loop.close()
def test_signal_has_receivers_when_is_true(): test_signal = Signal() test_signal.connect(sender=Sender, receiver=coroutine_receiver) assert test_signal.has_receivers(sender=Sender) is True
def test_signal_has_receivers_when_is_false(): test_signal = Signal() assert test_signal.has_receivers(sender=Sender) is False
def test_when_signal_connect_sender_is_a_function(): test_signal = Signal() test_signal.connect(sender=sender_function, receiver=coroutine_receiver) key = get_sender_key(sender_function) assert coroutine_receiver in test_signal.receivers[key]
def test_signal_connect_when_is_coroutine(): test_signal = Signal() test_signal.connect(sender=Sender, receiver=coroutine_receiver) key = get_sender_key(Sender) assert coroutine_receiver in test_signal.receivers[key]
def test_signal_connect_when_isnt_coroutine(): with pytest.raises(ArgumentError): test_signal = Signal() test_signal.connect(sender=Sender, receiver=not_coroutine_receiver)
def test_signal_dispatch_with_wrong_arguments(): with pytest.raises(ArgumentError): test_signal = Signal() test_signal.dispatch(sender=Sender, some_arg=True)