testutils: Add assert_dict_has
This is a convenient way for tests to assert that some nested dicts (like a parsed json) has a particular key/value somewhere in it. For example: assert_dict_has(config, "toplevel.subitem.key", True)
This commit is contained in:
parent
2d12ef478e
commit
eea81b660a
1 changed files with 7 additions and 0 deletions
|
|
@ -6,3 +6,10 @@ import shutil
|
|||
|
||||
def has_executable(executable: str) -> bool:
|
||||
return shutil.which(executable) is not None
|
||||
|
||||
|
||||
def assert_dict_has(v, keys, expected_value):
|
||||
for key in keys.split("."):
|
||||
assert key in v
|
||||
v = v[key]
|
||||
assert v == expected_value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue