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:
Alexander Larsson 2023-12-08 09:21:36 +01:00 committed by Michael Vogt
parent 2d12ef478e
commit eea81b660a

View file

@ -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