def test_byte_construction_with_header_single_data_byte_invalid_checksum( self): with self.assertRaises(ValueError): Packet([ 0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, REMOTE_CONTROL, 1, ON, 2, 43 ])
def test_byte_construction_with_header_multiple_data_bytes_invalid_checksum( self): with self.assertRaises(ValueError): Packet([ 0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, PUMP_PROGRAM, 4, SET, RPM, 5, 220, 2, 211 ])
def test_kv_construction_multiple_data_bytes(self): packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220]) self.assertEqual(packet.dst, DST) self.assertEqual(packet.src, SRC) self.assertEqual(packet.action, PUMP_PROGRAM) self.assertEqual(packet.data_length, 4) self.assertEqual(packet.data, [SET, RPM, 5, 220]) self.assertEqual(packet.bytes, [ 0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, PUMP_PROGRAM, 4, SET, RPM, 5, 220, 2, 210 ])
def test_byte_construction_no_header_single_data_byte_valid_checksum(self): packet = Packet([DST, SRC, REMOTE_CONTROL, 1, ON, 2, 42]) self.assertEqual(packet.dst, DST) self.assertEqual(packet.src, SRC) self.assertEqual(packet.action, REMOTE_CONTROL) self.assertEqual(packet.data_length, 1) self.assertEqual(packet.data, [ON]) self.assertEqual(packet.bytes, [ 0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, REMOTE_CONTROL, 1, ON, 2, 42 ])
def test_byte_construction_no_header_multiple_data_bytes_no_checksum(self): packet = Packet([DST, SRC, PUMP_PROGRAM, 4, SET, RPM, 5, 220]) self.assertEqual(packet.dst, DST) self.assertEqual(packet.src, SRC) self.assertEqual(packet.action, PUMP_PROGRAM) self.assertEqual(packet.data_length, 4) self.assertEqual(packet.data, [SET, RPM, 5, 220]) self.assertEqual(packet.bytes, [ 0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, PUMP_PROGRAM, 4, SET, RPM, 5, 220, 2, 210 ])
def test_kv_construction_no_data(self): packet = Packet(dst=DST, action=GET_PUMP_STATUS) self.assertEqual(packet.dst, DST) self.assertEqual(packet.src, SRC) self.assertEqual(packet.action, GET_PUMP_STATUS) self.assertEqual(packet.data_length, 0) self.assertEqual(packet.data, None) self.assertEqual(packet.bytes, [ 0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, GET_PUMP_STATUS, 0, 1, 45 ])
def test_kv_construction_single_data_byte_list(self): packet = Packet(dst=DST, action=REMOTE_CONTROL, data=[ON]) self.assertEqual(packet.dst, DST) self.assertEqual(packet.src, SRC) self.assertEqual(packet.action, REMOTE_CONTROL) self.assertEqual(packet.data_length, 1) self.assertEqual(packet.data, [ON]) self.assertEqual(packet.bytes, [ 0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, REMOTE_CONTROL, 1, ON, 2, 42 ])
def test_byte_construction_no_header_no_data_valid_checksum(self): packet = Packet([DST, SRC, GET_PUMP_STATUS, 0, 1, 45]) self.assertEqual(packet.dst, DST) self.assertEqual(packet.src, SRC) self.assertEqual(packet.action, GET_PUMP_STATUS) self.assertEqual(packet.data_length, 0) self.assertEqual(packet.data, None) self.assertEqual(packet.bytes, [ 0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, GET_PUMP_STATUS, 0, 1, 45 ])
def test_data_length_with_multiple_data_bytes(self): packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220]) self.assertEqual(packet.data_length, 4)
def test_byte_construction_no_header_single_data_byte_invalid_checksum( self): with self.assertRaises(ValueError): Packet([DST, SRC, REMOTE_CONTROL, 1, ON, 2, 43])
def test_byte_construction_with_header_no_data_invalid_checksum(self): with self.assertRaises(ValueError): Packet([ 0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, GET_PUMP_STATUS, 0, 1, 46 ])
def test_byte_construction_no_header_no_data_invalid_checksum(self): with self.assertRaises(ValueError): Packet([DST, SRC, GET_PUMP_STATUS, 0, 1, 46])
def test_payload_with_single_data_byte_list(self): packet = Packet(dst=DST, action=REMOTE_CONTROL, data=[ON]) self.assertEqual( packet.payload, [PAYLOAD_HEADER, VERSION, DST, SRC, REMOTE_CONTROL, 1, ON])
def test_data_length_with_single_data_byte_list(self): packet = Packet(dst=DST, action=REMOTE_CONTROL, data=[ON]) self.assertEqual(packet.data_length, 1)
def test_checksum(self): packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220]) self.assertEqual(packet.checksum, 2 * 256 + 210)
def test_checkbytes(self): packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220]) self.assertEqual(packet.checkbytes, [2, 210])
def test_payload_with_multiple_data_bytes(self): packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220]) self.assertEqual(packet.payload, [ PAYLOAD_HEADER, VERSION, DST, SRC, PUMP_PROGRAM, 4, SET, RPM, 5, 220 ])
def test_byte_construction_no_header_multiple_data_bytes_invalid_checksum( self): with self.assertRaises(ValueError): Packet([DST, SRC, PUMP_PROGRAM, 4, SET, RPM, 5, 220, 2, 211])
def test_data_length_with_no_data(self): packet = Packet(dst=DST, action=GET_PUMP_STATUS) self.assertEqual(packet.data_length, 0)
def test_payload_with_no_data(self): packet = Packet(dst=DST, action=GET_PUMP_STATUS) self.assertEqual( packet.payload, [PAYLOAD_HEADER, VERSION, DST, SRC, GET_PUMP_STATUS, 0])