def test_connect(monkeypatch): portmock = mock.MagicMock() appmock = mock.MagicMock() async def mockconnect(loop, protocol_factory, **kwargs): protocol = protocol_factory() loop.call_soon(protocol.connection_made, None) return None, protocol monkeypatch.setattr( serial_asyncio, 'create_serial_connection', mockconnect, ) loop = asyncio.get_event_loop() loop.run_until_complete(uart.connect(portmock, 115200, appmock))
def connect(self, device, baudrate): assert self._gw is None self._gw = yield from uart.connect(device, baudrate, self)