Skip to content

Commit

Permalink
testutils: Add assert_dict_has
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
alexlarsson committed Dec 8, 2023
1 parent 4d66c61 commit c4914fb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions osbuild/testutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@

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

0 comments on commit c4914fb

Please sign in to comment.