veilid/veilid-python/tests/__init__.py

35 lines
1019 B
Python
Raw Normal View History

2023-06-16 00:22:54 +00:00
from typing import Callable, Awaitable
import os
2023-06-15 01:06:10 +00:00
import pytest
pytest_plugins = ('pytest_asyncio',)
2023-06-16 00:22:54 +00:00
import veilid
2023-06-15 01:06:10 +00:00
##################################################################
VEILID_SERVER = os.getenv("VEILID_SERVER")
if VEILID_SERVER is not None:
vsparts = VEILID_SERVER.split(":")
VEILID_SERVER = vsparts[0]
if len(vsparts) == 2:
VEILID_SERVER_PORT = int(vsparts[1])
else:
VEILID_SERVER_PORT = 5959
else:
VEILID_SERVER = "localhost"
VEILID_SERVER_PORT = 5959
##################################################################
2023-06-16 00:22:54 +00:00
async def simple_connect_and_run(func: Callable[[veilid.VeilidAPI], Awaitable]):
api = await veilid.json_api_connect(VEILID_SERVER, VEILID_SERVER_PORT, simple_update_callback)
async with api:
2023-06-16 17:14:34 +00:00
# purge routes to ensure we start fresh
await api.debug("purge routes")
2023-06-16 00:22:54 +00:00
await func(api)
async def simple_update_callback(update: veilid.VeilidUpdate):
2023-06-15 01:06:10 +00:00
print("VeilidUpdate: {}".format(update))