def testSerialAsyncioClient(self, mock_gather, mock_event_loop, method, framer): """ Test that AsyncModbusSerialClient instantiates AsyncioModbusSerialClient for asyncio scheduler. :return: """ loop = asyncio.get_event_loop() loop.is_running.side_effect = lambda: False loop, client = AsyncModbusSerialClient(schedulers.ASYNC_IO, method=method, port=SERIAL_PORT, loop=loop, baudrate=19200, parity='E', stopbits=2, bytesize=7) assert (isinstance(client, AsyncioModbusSerialClient)) assert (isinstance(client.framer, framer)) assert (client.port == SERIAL_PORT) assert (client.baudrate == 19200) assert (client.parity == 'E') assert (client.stopbits == 2) assert (client.bytesize == 7) client.stop() loop.stop()
def testSerialTwistedClient(self, method, framer): """ Test the serial twisted client client initialize """ from serial import Serial with patch("serial.Serial") as mock_sp: from twisted.internet import reactor from twisted.internet.serialport import SerialPort with patch('twisted.internet.reactor') as mock_reactor: protocol, client = AsyncModbusSerialClient(schedulers.REACTOR, method=method, port=SERIAL_PORT, proto_cls=ModbusSerClientProtocol) assert (isinstance(client, SerialPort)) assert (isinstance(client.protocol, ModbusSerClientProtocol)) assert (0 == len(list(client.protocol.transaction))) assert (isinstance(client.protocol.framer, framer)) assert (client.protocol._connected) def handle_failure(failure): assert (isinstance(failure.exception(), ConnectionException)) d = client.protocol._buildResponse(0x00) d.addCallback(handle_failure) assert (client.protocol._connected) client.protocol.close() protocol.stop() assert (not client.protocol._connected)
def testSerialTornadoClient(self, method, framer): """ Test the serial tornado client client initialize """ from serial import Serial with maybe_manage(sys.platform in ('darwin', 'win32'), patch.object(Serial, "open")): protocol, future = AsyncModbusSerialClient(schedulers.IO_LOOP, method=method, port=SERIAL_PORT) client = future.result() assert (isinstance(client, AsyncTornadoModbusSerialClient)) assert (0 == len(list(client.transaction))) assert (isinstance(client.framer, framer)) assert (client.port == SERIAL_PORT) assert (client._connected) def handle_failure(failure): assert (isinstance(failure.exception(), ConnectionException)) d = client._build_response(0x00) d.add_done_callback(handle_failure) assert (client._connected) client.close() protocol.stop() assert (not client._connected)
def testSerialTornadoClient(self, method, framer): """ Test the serial tornado client client initialize """ protocol, future = AsyncModbusSerialClient(schedulers.IO_LOOP, method=method, port=SERIAL_PORT) client = future.result() assert(isinstance(client, AsyncTornadoModbusSerialClient)) assert(0 == len(list(client.transaction))) assert(isinstance(client.framer, framer)) assert(client.port == SERIAL_PORT) assert(client._connected) def handle_failure(failure): assert(isinstance(failure.exception(), ConnectionException)) d = client._build_response(0x00) d.add_done_callback(handle_failure) assert(client._connected) client.close() protocol.stop() assert(not client._connected)