def testBitReadBaseRequestEncoding(self): ''' Test basic bit message encoding/decoding ''' for i in range(20): handle = ReadBitsRequestBase(i, i) result = struct.pack('>HH', i, i) self.assertEqual(handle.encode(), result) handle.decode(result) self.assertEqual((handle.address, handle.count), (i, i))
def testBitReadBaseRequestEncoding(self): ''' Test basic bit message encoding/decoding ''' for i in range(20): handle = ReadBitsRequestBase(i, i) result = struct.pack('>HH',i, i) self.assertEqual(handle.encode(), result) handle.decode(result) self.assertEqual((handle.address, handle.count), (i,i))
def testBitReadBaseRequests(self): ''' Test bit read request encoding ''' messages = { ReadBitsRequestBase(12, 14): b'\x00\x0c\x00\x0e', ReadBitsResponseBase([1, 0, 1, 1, 0]): b'\x01\x0d' } for request, expected in iteritems(messages): self.assertEqual(request.encode(), expected)
def testReadBitBaseClassMethods(self): ''' Test basic bit message encoding/decoding ''' handle = ReadBitsRequestBase(1, 1) msg = "ReadBitRequest(1,1)" self.assertEqual(msg, str(handle)) handle = ReadBitsResponseBase([1, 1]) msg = "ReadBitResponse(2)" self.assertEqual(msg, str(handle))