Testing API¶
labnet.testing helps test drivers and code that uses LabNet.
drivers ¶
check_driver: would a Lab PC accept this device? Ask the Lab PC's own checks.
DriverCheckError ¶
Bases: AssertionError
A device that a Lab PC would refuse or fail to start.
check_driver ¶
check_driver(device: PhysicalDevice, *, timeout: float = 30.0) -> DeviceSnapshot
:func:acheck_driver for synchronous code (not inside a running event loop).
acheck_driver
async
¶
acheck_driver(device: PhysicalDevice, *, timeout: float = 30.0) -> DeviceSnapshot
Start device exactly as a Lab PC would, then stop it; return what it published.
The device must have a registered contract, implement every method that
contract names with matching arguments, connect, report a status and an
availability, and publish JSON metadata whose hints fit the contract (site
limits included). Raises :class:DriverCheckError saying what is wrong.
network ¶
local_network: a real Central and one Lab PC in this process, for tests and demos.
Both run as Uvicorn servers in background threads, set up the way an operator
would (labnet-central-admin setup --write-env plus a Lab PC env file), so
client code connects to them exactly as it would in the lab: through a user's
env file (LABNET_ENV_FILE). Needs labnet[central,lab-pc].
LocalNetwork
dataclass
¶
LocalNetwork(root: Path, central_url: str, lab_pc_id: str, env_files: dict[str, Path] = dict())
Where a running :func:local_network is, and each user's env file.
local_network ¶
local_network(devices: Callable[[], Iterable[PhysicalDevice]], root: Path, *, users: Sequence[str] = ('researcher',), lab_pc_id: str = 'lab-pc-test') -> Iterator[LocalNetwork]
Run Central and a Lab PC serving devices() until the block ends.
root (an empty folder) receives the database and env files. Each name
in users gets an API key and <root>/<user>.env.