コード例 #1
0
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()
コード例 #2
0
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
コード例 #3
0
def test_signal_has_receivers_when_is_false():
    test_signal = Signal()
    assert test_signal.has_receivers(sender=Sender) is False
コード例 #4
0
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]
コード例 #5
0
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]
コード例 #6
0
def test_signal_connect_when_isnt_coroutine():
    with pytest.raises(ArgumentError):
        test_signal = Signal()
        test_signal.connect(sender=Sender, receiver=not_coroutine_receiver)
コード例 #7
0
def test_signal_dispatch_with_wrong_arguments():
    with pytest.raises(ArgumentError):
        test_signal = Signal()
        test_signal.dispatch(sender=Sender, some_arg=True)