Exemplo n.º 1
0
def test_sequence_increment():
    # Test that the sequence number can be increased and the wrap around at 255 is correct
    built_packet = DataPacket(cid=(16, 1, 15, 2, 14, 3, 13, 4, 12, 5, 11, 6,
                                   10, 7, 9, 8),
                              sourceName='Test Name',
                              universe=30)
    built_packet.sequence = 78
    built_packet.sequence_increase()
    assert built_packet.sequence == 79
    built_packet.sequence = 255
    built_packet.sequence_increase()
    assert built_packet.sequence == 0
Exemplo n.º 2
0
def test_remove_listener_from_universe():
    receiver, socket = get_receiver()

    test_universe_one = 1
    test_universe_two = 2

    packet_send = DataPacket(cid=tuple(range(0, 16)),
                             sourceName='Test',
                             universe=test_universe_one,
                             dmxData=tuple(range(0, 16)))

    called = 0

    def callback_packet(packet):
        assert packet_send.__dict__ == packet.__dict__
        nonlocal called
        called += 1

    # register listener multiple times
    receiver.register_listener('universe',
                               callback_packet,
                               universe=test_universe_one)
    receiver.register_listener('universe',
                               callback_packet,
                               universe=test_universe_two)

    packet_send.universe = test_universe_one
    socket.call_on_data(bytes(packet_send.getBytes()), 0)
    assert called == 1
    packet_send.universe = test_universe_two
    socket.call_on_data(bytes(packet_send.getBytes()), 0)
    assert called == 2

    # change DMX data to trigger a change
    packet_send.dmxData = tuple(range(16, 32))
    packet_send.sequence_increase()

    test_universe_removed = test_universe_one
    receiver.remove_listener_from_universe(test_universe_removed)

    # removing from a universe that does not exist, should do nothing
    receiver.remove_listener_from_universe(12345)

    # call to the removed universe should not happen
    packet_send.universe = test_universe_removed
    socket.call_on_data(bytes(packet_send.getBytes()), 0)
    assert called == 2
    # other universes should not be affected
    packet_send.universe = test_universe_two
    socket.call_on_data(bytes(packet_send.getBytes()), 0)
    assert called == 3
Exemplo n.º 3
0
def test_universe_stream_terminated():
    _, listener, socket = get_handler()
    assert listener.on_availability_change_changed is None
    assert listener.on_availability_change_universe is None
    packet = DataPacket(cid=tuple(range(0, 16)),
                        sourceName='Test',
                        universe=1,
                        dmxData=tuple(range(0, 16)))
    socket.call_on_data(bytes(packet.getBytes()), 0)
    assert listener.on_availability_change_changed == 'available'
    assert listener.on_availability_change_universe == 1
    packet.sequence_increase()
    packet.option_StreamTerminated = True
    socket.call_on_data(bytes(packet.getBytes()), 0)
    assert listener.on_availability_change_changed == 'timeout'
    assert listener.on_availability_change_universe == 1
Exemplo n.º 4
0
def test_remove_listener():
    receiver, socket = get_receiver()

    packetSend = DataPacket(cid=tuple(range(0, 16)),
                            sourceName='Test',
                            universe=1,
                            dmxData=tuple(range(0, 16)))

    called = 0

    def callback_packet(packet):
        assert packetSend.__dict__ == packet.__dict__
        nonlocal called
        called += 1

    # register listener multiple times
    receiver.register_listener('universe',
                               callback_packet,
                               universe=packetSend.universe)
    receiver.register_listener('universe',
                               callback_packet,
                               universe=packetSend.universe)

    socket.call_on_data(bytes(packetSend.getBytes()), 0)
    assert called == 2

    # change DMX data to trigger a change
    packetSend.dmxData = tuple(range(16, 32))
    packetSend.sequence_increase()

    receiver.remove_listener(callback_packet)

    # removing a listener does not exist, should do nothing
    receiver.remove_listener(None)

    socket.call_on_data(bytes(packetSend.getBytes()), 0)
    assert called == 2