2023-07-21 19:54:32 -04:00
|
|
|
"""Common test fixtures."""
|
|
|
|
|
2023-06-17 14:37:39 -04:00
|
|
|
from typing import AsyncGenerator
|
|
|
|
|
2023-07-21 19:54:32 -04:00
|
|
|
import pytest
|
2023-06-17 14:37:39 -04:00
|
|
|
import pytest_asyncio
|
|
|
|
|
2023-07-21 19:54:32 -04:00
|
|
|
import veilid
|
2024-08-13 16:47:06 -04:00
|
|
|
from veilid.json_api import _JsonVeilidAPI
|
2023-06-17 14:37:39 -04:00
|
|
|
|
|
|
|
|
2023-07-21 19:54:32 -04:00
|
|
|
pytest_plugins = ("pytest_asyncio",)
|
2023-06-17 14:37:39 -04:00
|
|
|
|
|
|
|
|
|
|
|
async def simple_update_callback(update: veilid.VeilidUpdate):
|
|
|
|
print(f"VeilidUpdate: {update}")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
|
|
async def api_connection() -> AsyncGenerator[_JsonVeilidAPI, None]:
|
2023-07-21 19:54:32 -04:00
|
|
|
try:
|
2024-08-13 16:08:15 -04:00
|
|
|
api = await veilid.api_connector(simple_update_callback)
|
|
|
|
except veilid.VeilidConnectionError:
|
2023-07-21 19:54:32 -04:00
|
|
|
pytest.skip("Unable to connect to veilid-server.")
|
|
|
|
|
2023-06-17 14:37:39 -04:00
|
|
|
async with api:
|
|
|
|
# purge routes to ensure we start fresh
|
|
|
|
await api.debug("purge routes")
|
|
|
|
|
|
|
|
yield api
|