def test_packet_enc_dec(self): packets_type_data = [ ( PacketsTestCase.GOOD_STR_TYPE, PacketsTestCase.GOOD_STR_DATA ), ( PacketsTestCase.GOOD_BIN_TYPE, PacketsTestCase.GOOD_BIN_DATA ), ] for i, packet_type_data in enumerate(packets_type_data): self.assertEqual(packet_type_data, deceiopacket(enceiopacket(*packet_type_data)), msg='packet_type_data[{}]: {!r}'.format(i, packet_type_data))
def test_packet_dec_enc(self): packets = [ PacketsTestCase.GOOD_STR_PACKET, PacketsTestCase.GOOD_BIN_PACKET, ] for i, packet in enumerate(packets): self.assertEqual(packet, enceiopacket(*deceiopacket(packet)), msg='packet[{}]: {!r}'.format(i, packet))
def test_packet_enc_bad_type(self): packets_type_data = [ ( PacketsTestCase.BAD_TYPE, PacketsTestCase.GOOD_STR_DATA ), ( PacketsTestCase.BAD_TYPE, PacketsTestCase.GOOD_BIN_DATA ), ] for i, packet_type_data in enumerate(packets_type_data): with self.assertRaisesRegex(PayloadEncodeError, r'^unrecognized packet type "', msg='packet_type_data[{}]: {!r}'.format(i, packet_type_data)): enceiopacket(*packet_type_data) packets_type_data = [ ( EIO_TYPE_CODES_BY_NAME['message'], list(range(10)) ), ( EIO_TYPE_CODES_BY_NAME['message'], tuple(range(10)) ), ( EIO_TYPE_CODES_BY_NAME['message'], 42 ), ] for i, packet_type_data in enumerate(packets_type_data): with self.assertRaisesRegex(TypeError, r'^packet_data type must be one of bytes or str, not .+$', msg='packet[{}]: {!r}'.format(i, packet_type_data)): enceiopacket(*packet_type_data)
def test_packet_enc(self): packets_type_data = [ ( PacketsTestCase.GOOD_STR_TYPE, PacketsTestCase.GOOD_STR_DATA ), ( PacketsTestCase.GOOD_BIN_TYPE, PacketsTestCase.GOOD_BIN_DATA ), ] packets = [ PacketsTestCase.GOOD_STR_PACKET, PacketsTestCase.GOOD_BIN_PACKET, ] for i, zipped in enumerate(zip(packets, packets_type_data)): expected, packet_type_data = zipped self.assertEqual(expected, enceiopacket(*packet_type_data), msg='packet_type_data[{}]: {!r}'.format(i, packet_type_data))
def test_enc_dec(self, packet_type, packet_data): args = ( packet_type, packet_data ) self.assertEqual(args, deceiopacket(enceiopacket(*args)))