def testConnectionMade(self): protocol = ModbusTcpProtocol() protocol.transport = MagicMock() protocol.factory = MagicMock() protocol.factory.framer = ModbusSocketFramer protocol.connectionMade() self.assertIsInstance(protocol.framer, ModbusSocketFramer)
def testSendTcp(self): class MockMsg(object): def __init__(self, msg, resp=False): self.should_respond = resp self.msg = msg mock_msg = b"\x00\x01\x12\x34\x00\x04\xff\x02\x12\x34" protocol = ModbusTcpProtocol() mock_data = MockMsg(resp=True, msg=mock_msg) protocol.control = MagicMock() protocol.framer = MagicMock() protocol.factory = MagicMock() protocol.framer.buildPacket = MagicMock(return_value=mock_msg) protocol.transport = MagicMock() protocol._send(mock_data) self.assertTrue(protocol.framer.buildPacket.called) self.assertTrue(protocol.transport.write.called) mock_data = MockMsg(resp=False, msg="helloworld") self.assertEqual(protocol._send(mock_data), None)
def testSendTcp(self): class MockMsg(object): def __init__(self, msg, resp=False): self.should_respond = resp self.msg = msg mock_msg = b"\x00\x01\x12\x34\x00\x04\xff\x02\x12\x34" protocol = ModbusTcpProtocol() mock_data = MockMsg(resp=True, msg=mock_msg) protocol.control = MagicMock() protocol.framer = MagicMock() protocol.factory = MagicMock() protocol.framer.buildPacket = MagicMock(return_value=mock_msg) protocol.transport= MagicMock() protocol._send(mock_data) self.assertTrue(protocol.framer.buildPacket.called) self.assertTrue(protocol.transport.write.called) mock_data =MockMsg(resp=False, msg="helloworld") self.assertEqual(protocol._send(mock_data), None)