Skip to content

pytest

random_hex

random_hex(length: int) -> str

Return random hex string of given length.

Source code in src/metador_core/util/pytest.py
4
5
6
def random_hex(length: int) -> str:
    """Return random hex string of given length."""
    return secrets.token_hex(length // 2 + 1)[:length]

parameters

parameters(d, keys=None)

Expand parameter combinations from a nested dict into a list of tuples.

Source code in src/metador_core/util/pytest.py
 9
10
11
12
13
14
15
16
17
def parameters(d, keys=None):
    """Expand parameter combinations from a nested dict into a list of tuples."""
    keys = keys or []
    if isinstance(d, list):
        return sum((parameters(y, keys) for y in d), [])
    elif isinstance(d, dict):
        return sum((parameters(v, keys + [k]) for k, v in d.items()), [])
    else:
        return [tuple(keys + [d])]