def testTcpExecuteFailure(self): protocol = ModbusTcpProtocol() protocol.factory = MagicMock() protocol.factory.store = MagicMock() protocol.store = MagicMock() protocol.factory.ignore_missing_slaves = False request = MagicMock() protocol._send = MagicMock() # CASE-1: test NoSuchSlaveException exceptions request.execute.side_effect = NoSuchSlaveException() self.assertRaises( NoSuchSlaveException, protocol._execute(request) ) self.assertTrue(request.doException.called) # CASE-2: NoSuchSlaveException with ignore_missing_slaves = true protocol.ignore_missing_slaves = True request.execute.side_effect = NoSuchSlaveException() self.assertEqual(protocol._execute(request), None) # test other exceptions request.execute.side_effect = ModbusIOException() self.assertRaises( ModbusIOException, protocol._execute(request) ) self.assertTrue(protocol._send.called)
def testTcpExecuteSuccess(self): protocol = ModbusTcpProtocol() protocol.store = MagicMock() request = MagicMock() protocol._send = MagicMock() # tst if _send being called protocol._execute(request) self.assertTrue(protocol._send.called)
def testTcpExecuteSuccess(self): protocol = ModbusTcpProtocol() protocol.store = MagicMock() request = MagicMock() protocol._send = MagicMock() # tst if _send being called protocol._execute(request) self.assertTrue(protocol._send.called)
def testTcpExecuteFailure(self): protocol = ModbusTcpProtocol() protocol.store = MagicMock() request = MagicMock() protocol._send = MagicMock() # CASE-1: test NoSuchSlaveException exceptions request.execute.side_effect = NoSuchSlaveException() self.assertRaises(NoSuchSlaveException, protocol._execute(request)) self.assertTrue(request.doException.called) # CASE-2: NoSuchSlaveException with ignore_missing_slaves = true protocol.ignore_missing_slaves = True request.execute.side_effect = NoSuchSlaveException() self.assertEqual(protocol._execute(request), None) # test other exceptions request.execute.side_effect = ModbusIOException() self.assertRaises(ModbusIOException, protocol._execute(request)) self.assertTrue(protocol._send.called)