def test_property_adjustment_and_deconstruction(): # Converting DataPacket -> bytes -> DataPacket should produce the same result, # but with changed properties that are not the default 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.cid = tuple(range(16)) built_packet.sourceName = '2nd Test Name' built_packet.universe = 31425 built_packet.dmxData = ((200, ) + tuple(range(255, 0, -1)) + tuple(range(255)) + (0, )) built_packet.priority = 12 built_packet.sequence = 45 built_packet.option_StreamTerminated = True built_packet.option_PreviewData = True built_packet.option_ForceSync = True built_packet.syncAddr = 34003 built_packet.dmxStartCode = 8 read_packet = DataPacket.make_data_packet(built_packet.getBytes()) assert read_packet.cid == tuple(range(16)) assert read_packet.sourceName == '2nd Test Name' assert read_packet.universe == 31425 assert read_packet.dmxData == ((200, ) + tuple(range(255, 0, -1)) + tuple(range(255)) + (0, )) assert read_packet.priority == 12 assert read_packet.sequence == 45 assert read_packet.option_StreamTerminated is True assert read_packet.option_PreviewData is True assert read_packet.option_ForceSync is True assert read_packet.syncAddr == 34003 assert read_packet.dmxStartCode == 8
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
def test_possible_universes(): handler, _, socket = get_handler() assert handler.get_possible_universes() == [] packet = DataPacket(cid=tuple(range(0, 16)), sourceName='Test', universe=1, dmxData=tuple(range(0, 16))) # add universe 1 socket.call_on_data(bytes(packet.getBytes()), 0) assert handler.get_possible_universes() == [1] # add universe 2 packet.universe = 2 socket.call_on_data(bytes(packet.getBytes()), 0) assert handler.get_possible_universes() == [1, 2] # remove universe 2 packet.option_StreamTerminated = True socket.call_on_data(bytes(packet.getBytes()), 0) assert handler.get_possible_universes() == [1]