Coverage for src/metador_core/util/pytest.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-02 09:33 +0000

1import secrets 

2 

3 

4def random_hex(length: int) -> str: 

5 """Return random hex string of given length.""" 

6 return secrets.token_hex(length // 2 + 1)[:length] 

7 

8 

9def parameters(d, keys=None): 

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

11 keys = keys or [] 

12 if isinstance(d, list): 

13 return sum((parameters(y, keys) for y in d), []) 

14 elif isinstance(d, dict): 

15 return sum((parameters(v, keys + [k]) for k, v in d.items()), []) 

16 else: 

17 return [tuple(keys + [d])]