async def test_discover_wifi(discover_wifi_app,
                             client,
                             tcp_create_connection_mock,
                             serial_create_connection_mock):
    spock = communication.get_conduit(discover_wifi_app)
    await asyncio.sleep(0.1)

    assert serial_create_connection_mock.call_count == 0
    assert tcp_create_connection_mock.call_count == 1
    assert spock.connected
async def test_discover_usb(discover_usb_app,
                            client,
                            mocker,
                            tcp_create_connection_mock,
                            serial_create_connection_mock):
    spock = communication.get_conduit(discover_usb_app)
    await asyncio.sleep(0.1)

    assert spock.connected
    assert tcp_create_connection_mock.call_count == 0
    assert serial_create_connection_mock.call_count == 1

    mocker.patch(TESTED + '.discover_serial', CoroutineMock(return_value=None))
    spock._protocol.connection_lost(None)
    await asyncio.sleep(0.1)

    assert not spock.connected
    assert tcp_create_connection_mock.call_count == 0
    assert serial_create_connection_mock.call_count == 1
async def test_discover_all(discover_all_app,
                            client,
                            mocker,
                            tcp_create_connection_mock,
                            serial_create_connection_mock):
    spock = communication.get_conduit(discover_all_app)
    await asyncio.sleep(0.1)

    assert serial_create_connection_mock.call_count == 1
    assert tcp_create_connection_mock.call_count == 0
    assert spock.connected

    serial_create_connection_mock.side_effect = exceptions.ConnectionImpossible

    spock._protocol.connection_lost(None)
    await asyncio.sleep(0.1)

    assert spock.connected
    assert serial_create_connection_mock.call_count == 2
    assert tcp_create_connection_mock.call_count == 1
Beispiel #4
0
 async def startup(self, app: web.Application):
     await self.shutdown()
     self._conduit = communication.get_conduit(app)
     self._conduit.data_callbacks.add(self._on_data)
     self._conduit.event_callbacks.add(self._on_event)
     self._cleanup_task = await scheduler.create_task(app, self._cleanup())
async def bound_conduit(app, client, bound_collector):
    conduit = communication.get_conduit(app)
    conduit.event_callbacks.add(bound_collector.async_on_event)
    conduit.data_callbacks.add(bound_collector.async_on_data)

    return conduit