Repository navigation
API turboframe.testing.terminal
Source: turboframe/testing/terminal.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.
Acceptance tests in a real terminal: a pytest plugin.
An application's acceptance/conftest.py says:
pytest_plugins = ["turboframe.testing.terminal"]and its pyproject.toml names its variables' prefix (MYAPP gives
MYAPP_ACCEPTANCE_RUN, MYAPP_ACCEPTANCE_ARTIFACTS...):
[tool.pytest.ini_options]
turboframe_acceptance_prefix = "MYAPP"It needs tui-test and psutil (pip install "turboframe[terminal]").
Fixtures, in the order a test asks for them:
-
evidence: a folder for what explains a failure, copied to$<PREFIX>_ACCEPTANCE_ARTIFACTS/<test>/only when the test failed; -
checkpoint: the scenario's screens at its meaningful moments (Checkpoints), kept in$<PREFIX>_ACCEPTANCE_CHECKPOINTS/<test>/; -
box: aSandbox, the project folder and settings of this test only, whoserun_idmarks every process the test starts; -
no_process_left: fails the test when a marked process outlives it (and kills it); ask for it beforeterminal; -
terminal: a tui-test terminal; on a failure its trace and screen go to the evidence.
need(ok, reason) skips a test whose tool is missing, and fails it in CI ($<PREFIX>_ACCEPTANCE_STRICT=1). start, alt and exit_code drive the terminal; marked, left_behind, describe and kill find a test's processes; screen(app) is a Pilot-driven app's screen as text.
COLS, ROWS, Checkpoints, Sandbox, alt, describe, details, exit_code, kill, left_behind, marked, need, sandbox, screen, start, wait_none_left
120
34
class Checkpoints
Checkpoints(folder: Path, test: str)Screens of a scenario at its meaningful moments, kept whether it passes or fails: each as SVG (what a terminal shows) and as text, and a line of checkpoints.json with its order, name and caption. A checkpoint never waits or checks anything itself: it records the screen the scenario's own wait reached.
-
pilot(app, name: str, caption: str) -> None: The screen of an application driven by Pilot (in the test's process). -
async terminal(tt, name: str, caption: str) -> None: The screen of the application in a real terminal (tui-test).
class Sandbox
Sandbox(root: Path, home: Path, run_id: str, mark: str, extra: dict = <factory>)The project a test opens and the settings of this test only. mark, set to run_id, is inherited by every process the test starts, and every process those start.
env(base: dict | None = None) -> dict-
apply(monkeypatch) -> None: The same, for an application that runs in the test's own process (Pilot).
async def alt(tt, key: str) -> NoneAlt+key as one write, as a terminal sends it (tui-test's press("Alt+x") arrives as Esc, then x).
def describe(procs: list) -> strdef details(procs: list) -> strEach process as the evidence keeps it: pid, parent, state, start, folder and command line.
async def exit_code(tt) -> int | NoneThe program's own exit code (tui-test's get_exit_code is a shell command's).
def kill(procs: list) -> NoneCleanup after a failed check, so one test's leftovers never reach the next.
def left_behind(mark: str, run_id: str, evidence: Path, timeout: float) -> listThe marked processes still alive after timeout seconds; when there are any, what is known of each is written to evidence/processes.txt before anything kills them.
def marked(mark: str, run_id: str) -> listThe processes whose environment has mark=run_id, except this one (a Pilot journey runs the application in the test's process).
def need(ok: bool, reason: str) -> NoneA scenario's precondition on the machine: skipped locally without it, failed in CI ($<PREFIX>_ACCEPTANCE_STRICT=1), so a missing tool never passes as a skipped test.
def sandbox(tmp_path: Path, mark: str, name: str = 'project') -> Sandboxdef screen(app) -> strThe screen of an application driven by Pilot, as text: the lines Textual draws.
async def start(tt, command: str | list[str], box: Sandbox, *args: str, cols: int = 120, rows: int = 34) -> NoneStart command (a program, or a program and its first arguments) and args in the terminal, in the box's project, with its settings and mark.
def wait_none_left(mark: str, run_id: str, timeout: float) -> listThe marked processes still alive after timeout seconds (none: an empty list): the condition, polled until it holds or the deadline passes.
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links