def testUdpClientProtocolHandleResponse(self): ''' Test the udp client protocol handles responses ''' protocol = ModbusUdpClientProtocol() out = [] reply = ReadCoilsRequest(1, 1) reply.transaction_id = 0x00 # handle skipped cases protocol._handleResponse(None) protocol._handleResponse(reply) # handle existing cases d = protocol._buildResponse(0x00) d.addCallback(lambda v: out.append(v)) protocol._handleResponse(reply) self.assertEqual(out[0], reply)
def testBaseClientHandleResponse(self, mock_iostream, mock_ioloop): """ Test the BaseTornado client handles responses """ client = AsyncModbusTCPClient(port=5020) client.connect() out = [] reply = ReadCoilsRequest(1, 1) reply.transaction_id = 0x00 # handle skipped cases client._handle_response(None) client._handle_response(reply) # handle existing cases d = client._build_response(0x00) d.add_done_callback(lambda v: out.append(v)) client._handle_response(reply) self.assertEqual(out[0].result(), reply)
def testClientProtocolHandleResponse(self, protocol): ''' Test the client protocol handles responses ''' protocol = protocol() transport = mock.MagicMock() protocol.connection_made(transport=transport) reply = ReadCoilsRequest(1, 1) reply.transaction_id = 0x00 # handle skipped cases protocol._handleResponse(None) protocol._handleResponse(reply) # handle existing cases d = protocol._buildResponse(0x00) protocol._handleResponse(reply) result = d.result() assert result == reply
def testClientProtocolHandleResponse(self, protocol): ''' Test the client protocol handles responses ''' protocol = protocol() transport = mock.MagicMock() protocol.connection_made(transport=transport) reply = ReadCoilsRequest(1, 1) reply.transaction_id = 0x00 # if isinstance(protocol.create_future, mock.MagicMock): # import asyncio # protocol.create_future.return_value = asyncio.Future() # handle skipped cases protocol._handleResponse(None) protocol._handleResponse(reply) # handle existing cases d = protocol._buildResponse(0x00) protocol._handleResponse(reply) result = d.result() assert result == reply
def testSerialClientHandleResponse(self, mock_serial, mock_seriostream, mock_ioloop): """ Test the tornado serial client client handles responses """ client = AsyncModbusSerialClient(ioloop=schedulers.IO_LOOP, framer=ModbusRtuFramer( ClientDecoder()), port=SERIAL_PORT) client.connect() out = [] reply = ReadCoilsRequest(1, 1) reply.transaction_id = 0x00 # handle skipped cases client._handle_response(None) client._handle_response(reply) # handle existing cases d = client._build_response(0x00) d.add_done_callback(lambda v: out.append(v)) client._handle_response(reply) self.assertEqual(d.result(), reply)
def testSerialClientHandleResponse(self, mock_serial, mock_seriostream, mock_ioloop): """ Test the tornado serial client client handles responses """ client = AsyncModbusSerialClient(ioloop=schedulers.IO_LOOP, framer=ModbusRtuFramer( ClientDecoder()), port=SERIAL_PORT) client.connect() out = [] reply = ReadCoilsRequest(1, 1) reply.transaction_id = 0x00 # handle skipped cases client._handle_response(None) client._handle_response(reply) # handle existing cases d = client._build_response(0x00) d.add_done_callback(lambda v: out.append(v)) client._handle_response(reply) self.assertEqual(out[0].result(), reply)