tbottest.initconfig

helper functions

Values of the lab and the board configuration (ini or JSON) are read through these functions, or the methods of IniTBotConfig and IniConfig built on them, never through config_parser directly. Then the order of the sections (TC_BOARDNAME before TC, LABHOST_<labname> for the lab host) is known in one place.

tbottest.initconfig.init_get_config(cfgp: RawConfigParser, name: str, default: str) → str[source]

returns value of key name from configparser.

Searches the sections init_config_sections() returns, while a testcase runs first “TC_BOARDNAME.TESTCASENAME”, then “TC_BOARDNAME”, then “TC”. If not found, return default value. If the value is “None” return None

So what happens without the key is up to the testcase. The generic testcases pass a default that means “not set” and are decorated with tbottest.tc.generictestdef.require_cfg(), so they are skipped and tbottest.tc.generic_board.generic_lnx_all() counts them as skipped. A testcase that cannot do without the key should raise an exception, so it fails.

Parameters:
  • cfgp – current config parser

  • name – name of key

  • default – default value if key is not found

tbottest.initconfig.init_config_sections() → list[source]

returns the sections of the board configuration in the order init_get_config() searches them

While a testcase runs (see init_testcase()) first “TC_BOARDNAME.TESTCASENAME”, then “TC_BOARDNAME” and “TC”, else only the last two. There is deliberately no section “TC_TESTCASENAME” for all boards, a value for all boards goes into “TC”.

tbottest.initconfig.init_testcase(name: str)[source]

make name the testcase that runs now, for the duration of the with block, see init_config_sections(). At its end the name of an outer block is valid again.

Parameters:

name – name of the testcase

tbottest.initconfig.init_current_testcase()[source]

returns the name of the testcase that runs now, see init_testcase(), or None outside of a testcase

tbottest.initconfig.init_get_config_int(cfgp: RawConfigParser, name: str, default: str) → int[source]

returns value of key name as int, searched as init_get_config() does. If the value is “None” return None

Parameters:
  • cfgp – current config parser

  • name – name of key

  • default – default value if key is not found

tbottest.initconfig.init_get_config_literal(cfgp: RawConfigParser, name: str, default: str)[source]

returns value of key name read as Python literal with ast.literal_eval(), e.g. a list or a dictionary, searched as init_get_config() does. If the value is “None” return None

Parameters:
  • cfgp – current config parser

  • name – name of key

  • default – default value if key is not found, as string

tbottest.initconfig.init_get_config_bool(cfgp: RawConfigParser, name: str, default: bool) → bool[source]

returns the boolean value of key name from the sections init_get_config() searches, see init_config_to_bool()

Parameters:
  • cfgp – current config parser

  • name – name of key

  • default – value if the key is missing or “None”

tbottest.initconfig.init_get_config_keys(cfgp: RawConfigParser, prefix: str) → list[source]

returns the keys starting with prefix, from the sections init_get_config() searches.

Keys of the sections init_config_sections() returns, in this order, each key once, in the order of the file. Read their values with init_get_config(), so a key in an earlier section hides the same key in a later one.

Parameters:
  • cfgp – current config parser

  • prefix – start of the key names

tbottest.initconfig.init_lab_get_config(cfgp: ~configparser.RawConfigParser, name: str, default=<object object>)[source]

returns value of key name from configparser from section LABHOST or LABHOST_labname

Parameters:
  • cfgp – current config parser

  • name – name of key

  • default – default value if key is not found; without it a missing key raises RuntimeError

tbottest.initconfig.init_section_get_config(cfgp: ~configparser.RawConfigParser, section: str, name: str, default=<object object>)[source]

returns value of key name in section of the configparser, as it is written there (no conversion of “None”).

For the sections of tbot.ini outside the [TC] sections of the board ini, e.g. [BUILDHOST], [SSHMACHINE] or [PICOCOM_BOARDNAME].

Parameters:
  • cfgp – current config parser

  • section – name of the section

  • name – name of key

  • default – value if section or key is missing; without it a missing section or key raises RuntimeError

tbottest.initconfig.init_section_get_config_bool(cfgp: RawConfigParser, section: str, name: str, default: bool) → bool[source]

returns the boolean value of key name in section, see init_section_get_config() and init_config_to_bool()

Parameters:
  • cfgp – current config parser

  • section – name of the section

  • name – name of key

  • default – value if section or key is missing

tbottest.initconfig.init_config_to_bool(value: str) → bool[source]

returns the boolean of an ini value, as configparser reads it (1, yes, true, on and 0, no, false, off, any case)

Parameters:

value – value from the ini file

tbottest.initconfig.init_has_section(cfgp: RawConfigParser, section: str) → bool[source]

returns True if the configparser has section

Parameters:
  • cfgp – current config parser

  • section – name of the section

tbottest.initconfig.init_find_sections(cfgp: RawConfigParser, part: str) → list[source]

returns the names of the sections that contain part, in the order of the ini file

Parameters:
  • cfgp – current config parser

  • part – part of the section name, e.g. “BUILDHOST”

tbottest.initconfig.init_read_inifile(filename: str) → RawConfigParser[source]

returns a configparser with the ini file filename read, the way IniTBotConfig and IniConfig read theirs

For code that has to read an ini file before IniTBotConfig and IniConfig exist, e.g. set_board_cfg() in boardspecific.py. Read its values with the init_*_config functions.

Parameters:

filename – path of the ini file

tbottest.initconfig.init_read_jsonfile(filename: str, flags=None, tbotcfgp=None) → RawConfigParser[source]

returns a configparser with the JSON configuration filename

The file holds an object of sections, each an object of keys, as the ini file has them. Names and values get their expressions replaced, see init_config_substitute(), values become strings, see init_json_value_to_str(). configparser then interpolates ${key} and ${section:key} as for an ini file.

Parameters:
  • filename – path of the JSON file

  • flags – the tbot flags, default those of the command line

  • tbotcfgp – configparser of tbot.json, for the board file

tbottest.initconfig.init_read_configfile(filename: str, tbotcfgp=None) → RawConfigParser[source]

returns a configparser with the configuration file filename, JSON if its name ends in .json (init_read_jsonfile()), else ini (init_read_inifile()); in both the expressions of init_config_substitute() are replaced

Parameters:
  • filename – path of the file

  • tbotcfgp – configparser of tbot.ini or tbot.json, for the board file

tbottest.initconfig.init_config_substitute(text: str, flags, tbotcfgp=None, where: str = '') → str[source]

returns text with the expressions of a JSON configuration replaced

  • ${env:NAME} and ${env:NAME:-default}, the environment variable NAME

  • ${flag:NAME} and ${flag:NAME:-default}, the value of the tbot flag NAME:<value>, True for a flag NAME without value

  • ${lab:key}, key of the lab section of tbot.json (LABHOST or LABHOST_<labname>), only with tbotcfgp

  • ${tbot:SECTION:key}, key of SECTION of tbot.json, only with tbotcfgp

The default is only used, and only replaced, when the value is not set; without default a missing value raises RuntimeError. Expressions may be nested; any other ${…} stays for the interpolation of configparser (${key}, ${section:key}), with the expressions in it replaced, and $$ stays as it is.

Parameters:
  • text – value or name from the JSON file

  • flags – the tbot flags

  • tbotcfgp – configparser of tbot.json, for ${lab:} and ${tbot:}

  • where – file name for the error messages

tbottest.initconfig.init_substitute_configparser(cfgp: RawConfigParser, flags=None, tbotcfgp=None, where: str = '') → RawConfigParser[source]

returns a configparser with the expressions of init_config_substitute() replaced in the section names, keys and values of cfgp, so an ini file can use them as a JSON file does

Parameters:
  • cfgp – configparser of an ini file

  • flags – the tbot flags, default those of the command line

  • tbotcfgp – configparser of tbot.ini, for the board file

  • where – file name for the error messages

tbottest.initconfig.init_json_value_to_str(value, subst=None) → str[source]

returns a value of a JSON configuration as the string configparser holds, as the ini file would have it

Strings stay strings, true/false become True/False, null None, numbers their digits, lists and dictionaries their Python literal, which the code reads with ast.literal_eval as from an ini file.

Parameters:
  • value – value from the JSON file

  • subst – function that replaces the expressions in a string, see init_config_substitute()

tbottest.initconfig.init_config_to_json_dict(cfgp: RawConfigParser, resolved: bool = False) → dict[source]

returns the configuration of cfgp as the object of a JSON configuration, see init_read_jsonfile()

Values that are a Python list or dictionary become JSON lists and objects, every other value stays a string.

Parameters:
  • cfgp – configparser of an ini or JSON configuration

  • resolved – True gives the values interpolated, as tbot reads them (a reference that does not resolve stays as written); False as they are written, with ${…}

tbottest.initconfig.generic_get_boardname()[source]

return the boards name in your lab setup

setup the boardname through tbot.flag boardname, -f boardname:<NAME>

You can overwrite this by defining your own board_set_boardname() in boardspecific.py if you need another approach.

tbottest.initconfig.copy_file(filename, newfile)[source]

copy file filename to newfile

Parameters:
  • filename – full path and name of source file

  • newfile – full path and name of target file

tbottest.initconfig.replace_in_file(filename, string, newv)[source]

replace string in filename with string newv

Parameters:
  • filename – full path and name of source file

  • string – searchstring

  • newv – new value

tbottest.initconfig.find_in_file_and_append(filename, substring, append)[source]

append in file filename to the string substring the string append

Parameters:
  • filename – full path and name of source file

  • substring – string to which string append gets appended

  • append – appended string

tbottest.initconfig.find_in_file_and_delete(filename, substring)[source]

delete line in file filename when substring is found

Parameters:
  • filename – full path and name of source file

  • substring – substring which get searched

classes

class tbottest.initconfig.IniTBotConfig(*args, **kwargs)[source]

Bases: object

reads common tbot config

see: boardspecific runtime adaptions (ini files)

get_section_config(section: str, name: str, default=<object object>)[source]

returns value of key name in section of tbot.ini, see init_section_get_config()

Parameters:
  • section – name of the section

  • name – name of key

  • default – value if missing; without it a missing key raises

get_section_config_bool(section: str, name: str, default: bool) → bool[source]

returns the boolean value of key name in section of tbot.ini, see init_section_get_config_bool()

Parameters:
  • section – name of the section

  • name – name of key

  • default – value if missing

get_lab_config(name: str, default=<object object>)[source]

returns value of key name in the section of the lab host, see init_lab_get_config()

Parameters:
  • name – name of key

  • default – value if missing; without it a missing key raises

has_section(section: str) → bool[source]

returns True if tbot.ini has section

Parameters:

section – name of the section

find_sections(part: str) → list[source]

returns the names of the sections of tbot.ini that contain part

Parameters:

part – part of the section name

  • IniConfig - Init generic setup from BOARDNAME.ini.

class tbottest.initconfig.IniConfig(*args, **kwargs)[source]

Bases: object

reads board config

see: boardspecific runtime adaptions (ini files)

get_config(name: str, default: str)[source]

returns value of key name from configparser.

use internal function init_get_config

Parameters:
  • name – name of key

  • default – default value if key is not found

get_config_int(name: str, default: str)[source]

returns int value of key name from configparser.

use internal function init_get_config_int

Parameters:
  • name – name of key

  • default – default value if key is not found

get_config_literal(name: str, default: str)[source]

returns the value of key name read as Python literal.

use internal function init_get_config_literal

Parameters:
  • name – name of key

  • default – default value if key is not found, as string

get_config_bool(name: str, default: bool) → bool[source]

returns the boolean value of key name.

use internal function init_get_config_bool

Parameters:
  • name – name of key

  • default – value if the key is missing or “None”

get_config_keys(prefix: str)[source]

returns the keys starting with prefix.

use internal function init_get_config_keys

Parameters:

prefix – start of the key names

get_default_config(name: str, default: str)[source]

return value of key from “default” section with name “name”

Parameters:
  • name – name of key

  • default – default value if key is not found