1# This file contains type hints that can be prepended to Nix test scripts so they can be type
2# checked.
3
4from test_driver.debug import DebugAbstract
5from test_driver.driver import Driver
6from test_driver.vlan import VLan
7from test_driver.machine import Machine
8from test_driver.logger import AbstractLogger
9from typing import Callable, Iterator, ContextManager, Optional, List, Dict, Any, Union
10from typing_extensions import Protocol
11from pathlib import Path
12from unittest import TestCase
13
14
15class RetryProtocol(Protocol):
16 def __call__(self, fn: Callable, timeout: int = 900) -> None:
17 raise Exception("This is just type information for the Nix test driver")
18
19
20class PollingConditionProtocol(Protocol):
21 def __call__(
22 self,
23 fun_: Optional[Callable] = None,
24 *,
25 seconds_interval: float = 2.0,
26 description: Optional[str] = None,
27 ) -> Union[Callable[[Callable], ContextManager], ContextManager]:
28 raise Exception("This is just type information for the Nix test driver")
29
30
31class CreateMachineProtocol(Protocol):
32 def __call__(
33 self,
34 start_command: str | dict,
35 *,
36 name: Optional[str] = None,
37 keep_vm_state: bool = False,
38 ) -> Machine:
39 raise Exception("This is just type information for the Nix test driver")
40
41
42start_all: Callable[[], None]
43subtest: Callable[[str], ContextManager[None]]
44retry: RetryProtocol
45test_script: Callable[[], None]
46machines: List[Machine]
47vlans: List[VLan]
48driver: Driver
49log: AbstractLogger
50create_machine: CreateMachineProtocol
51run_tests: Callable[[], None]
52join_all: Callable[[], None]
53serial_stdout_off: Callable[[], None]
54serial_stdout_on: Callable[[], None]
55polling_condition: PollingConditionProtocol
56debug: DebugAbstract
57t: TestCase