tbot Module

tbot.testcase(tc: F) → F[source]

Decorate a function to make it a testcase.


def foobar_testcase(x: str) -> int:
    return int(x, 16)
tbot.acquire_lab() → tbot.selectable.LabHost[source]

Acquire a new connection to the LabHost.

If your LabHost is a SSHLabHost this will create a new ssh connection.

You should call this function as little as possible, because it can be very slow. If possible, try to reuse the labhost. A recipe for doing so is:

import typing
import tbot
from tbot.machine import linux

def my_testcase(
    lab: typing.Optional[linux.LabHost] = None,
) -> None:
    with lab or tbot.acquire_lab() as lh:
        # Your code goes here
Return type:tbot.machine.linux.LabHost
tbot.acquire_board(lh: tbot.selectable.LabHost) → tbot.selectable.Board[source]

Acquire a handle to the selected board.

The returned board must be used in a with statement to be powered on.

Return type:tbot.machine.board.Board
tbot.acquire_uboot(board: tbot.selectable.Board) → tbot.selectable.UBootMachine[source]

Acquire the board’s U-Boot shell.

As there can only be one instance of UBootMachine at a time, your testcases should optionally take the UBootMachine as a parameter. The recipe looks like this:

import contextlib
import typing
import tbot
from tbot.machine import board

def my_testcase(
    lab: typing.Optional[tbot.selectable.LabHost] = None,
    uboot: typing.Optional[board.UBootMachine] = None,
) -> None:
    with contextlib.ExitStack() as cx:
        lh = cx.enter_context(lab or tbot.acquire_lab())
        if uboot is not None:
            ub = uboot
            b = cx.enter_context(tbot.acquire_board(lh))
            ub = cx.enter_context(tbot.acquire_uboot(b))

Return type:tbot.machine.board.UBootMachine
tbot.acquire_linux(b: Union[tbot.selectable.Board, tbot.selectable.UBootMachine]) → tbot.selectable.LinuxMachine[source]

Acquire the board’s Linux shell.

Can either boot from a previously created U-Boot (if the implementation supports this) or directly.

To write testcases that work both from the commandline and when called from other testcases, use the following recipe:

import contextlib
import typing
import tbot
from tbot.machine import board

def test_testcase(
    lab: typing.Optional[tbot.selectable.LabHost] = None,
    board_linux: typing.Optional[board.LinuxMachine] = None,
) -> None:
    with contextlib.ExitStack() as cx:
        lh = cx.enter_context(lab or tbot.acquire_lab())
        if board_linux is not None:
            lnx = board_linux
            b = cx.enter_context(tbot.acquire_board(lh))
            lnx = cx.enter_context(tbot.acquire_linux(b))

Return type:tbot.machine.board.LinuxMachine

Flags that were set on the commandline using -f <flagname>

Check for a flag using:

if "flagname" in tbot.flags:


class tbot.selectable.LabHost[source]

Bases: tbot.machine.linux.lab.local.LocalLabHost, typing.ContextManager

Default LabHost type.

Might be replaced by another LabHost if one was selected on the commandline using -l <lab.py>

Create a new instance of a LocalLabHost.

class tbot.selectable.Board(lh: tbot.machine.linux.lab.machine.LabHost)[source]

Bases: tbot.machine.board.board.Board, typing.ContextManager

Dummy type that will be replaced by the actual selected board at runtime.

class tbot.selectable.UBootMachine(b: Any)[source]

Bases: tbot.machine.board.uboot.UBootMachine, typing.ContextManager

Dummy type that will be replaced by the actual selected U-Boot machine at runtime.

class tbot.selectable.LinuxMachine(b: Any)[source]

Bases: tbot.machine.board.linux.LinuxStandaloneMachine, typing.ContextManager

Dummy type that will be replaced by the actual selected Linux machine at runtime.


class tbot.log.EventIO(ty: List[str], initial: Union[str, termcolor2._C, None] = None, *, verbosity: tbot.log.Verbosity = <Verbosity.INFO: 1>, nest_first: Optional[str] = None, **kwargs)[source]

Bases: _io.StringIO

Stream for a log event.

Create a log event.

A log event is a io.StringIO and everything written to the stram will be added to the log event.

Parameters:initial (str) – Optional first line of the log event


log.IS_UNICODE = True

Boolean that is set if stdout supports unicode.

You should use tbot.log.u() instead of querying this flag.

log.IS_COLOR = True

Boolean that is set if tbot’s output should be colored.

You can use tbot.log.c as an easy way to colorize your strings.

tbot.log.u(with_unicode: str, without_unicode: str) → str[source]

Select a string depending on whether the terminal supports unicode.

  • with_unicode (str) – The string to be used if unicode is available
  • without_unicode (str) – The string to be used if unicode is not available
Return type:



The selected string

class tbot.log.c(s: str) → tbot.log.c

Color a string. Reexport from termcolor2


tbot.log.message(tbot.log.c("Message").yellow.bold + ": Hello World!")
Parameters:s (str) – The string that should be colored

Set the foreground-color to red


Set the foreground-color to green


Set the foreground-color to yellow


Set the foreground-color to blue


Set the foreground-color to magenta


Set the foreground-color to cyan


Set the foreground-color to white


Set the background-color to red


Set the background-color to green


Set the background-color to yellow


Set the background-color to blue


Set the background-color to magenta


Set the background-color to cyan


Set the background-color to white


Enable the bold attribute


Enable the dark attribute


Enable the underline attribute

Enable the blink attribute


Enable the reverse attribute


Enable the concealed attribute

Log Events

tbot.log.message(msg: Union[str, termcolor2._C], verbosity: tbot.log.Verbosity = <Verbosity.INFO: 1>) → tbot.log.EventIO[source]

Log a message.

  • msg (str) – The message
  • verbosity (Verbosity) – Message verbosity
tbot.log_event.command(mach: str, cmd: str) → tbot.log.EventIO[source]

Log a command’s execution.

  • mach (str) – Name of the machine the command is run on
  • cmd (str) – The command itself
Return type:



A stream that the output of the command should be written to.

tbot.log_event.testcase_begin(name: str) → None[source]

Log a testcase’s beginning.

Parameters:name (str) – Name of the testcase
tbot.log_event.testcase_end(name: str, duration: float, success: bool = True) → None[source]

Log a testcase’s end.

  • duration (float) – Time passed while this testcase ran
  • success (bool) – Whether the testcase succeeded