esptest.common.parser module

esptest.common.parser.expand_env_vars(data, env=None)[source]

Expand environment variables in ${VAR_NAME} form.

Only braced environment variables are expanded. Missing variables raise KeyError from the selected environment mapping.

Parameters:
Return type:

str

esptest.common.parser.get_zfill_len(data, force=False)[source]

Resolve the zero-fill width for the given expression.

  • If the expression ends with #<N>, return N (explicitly declared width).

  • Otherwise, when force=True, return the length of the longest numeric run found in the expression.

  • Return 0 in all other cases (no zero-fill).

Examples

“2-7#3” -> 3 “02-07” -> 2 (force=True) “1,2” -> 0

Parameters:
Return type:

int

esptest.common.parser.expand_to_list(data, valid_chars='')[source]

Expand a string expression into a list of tokens (string mode).

Index / slice / ! exclusion semantics are not enabled in this mode.

The default valid_chars is letters + digits + whitespace; a comma- separated segment is kept as a raw string token only if every one of its characters falls inside this set.

Parameters:
  • data (str) – The expression to parse.

  • valid_chars (str) – Character whitelist for raw string tokens; the default set is used when this is empty.

Returns:

A list of string tokens.

Return type:

List[str]

Examples

“a,b,c” -> [‘a’, ‘b’, ‘c’] “a1,b2” -> [‘a1’, ‘b2’] “2-5” -> [2, 3, 4, 5] # range syntax still applies

esptest.common.parser.parse_param_idx(data, max_len=None, sort=False, dedup=False, zfilled=False)[source]

Expand a parameter-index expression into an index list (index mode).

Supports Python-style slices, negative indices and ! exclusion. Equivalent to _expand_to_list_ex(data, ..., is_index=True, strip=True).

Parameters:
  • data (str) – The index expression, e.g. '0,2-7,!5', '::-1', '02-07'.

  • max_len (int | None) – Total length of the target sequence; required when the expression contains open-ended slices or negative indices.

  • sort (bool) – Whether to sort the result in ascending order.

  • dedup (bool) – Whether to de-duplicate the result (does not preserve order).

  • zfilled (bool) – Whether to zero-fill the output to the longest numeric width and emit strings; the element type becomes str only in this case.

Returns:

List[int] when zfilled=False; List[str] when zfilled=True.

Return type:

List[str | int]

Examples (max_len=10):

“3:,11-14” -> [3, 4, 5, 6, 7, 8, 9] “4::-1” -> [4, 3, 2, 1, 0] “0,2-7,!5” -> [0, 2, 3, 4, 6, 7] “!3,!7” -> [0, 1, 2, 4, 5, 6, 8, 9] “!3-7” -> [0, 1, 2, 8, 9] “02-07” -> [‘02’, ‘03’, ‘04’, ‘05’, ‘06’, ‘07’] (zfilled=True) “2-7#3” -> [‘002’, ‘003’, ‘004’, ‘005’, ‘006’, ‘007’]