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
KeyErrorfrom the selected environment mapping.
- 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>, returnN(explicitly declared width).Otherwise, when
force=True, return the length of the longest numeric run found in the expression.Return
0in all other cases (no zero-fill).
Examples
“2-7#3” -> 3 “02-07” -> 2 (force=True) “1,2” -> 0
- 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_charsisletters + 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:
- Returns:
A list of string tokens.
- Return type:
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
stronly in this case.
- Returns:
List[int]whenzfilled=False;List[str]whenzfilled=True.- Return type:
- 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’]