diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-07-25 11:11:05 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-07-25 11:38:57 +0300 |
commit | be53a50f86c3f9dcbc003d2ced9824829ee81f19 (patch) | |
tree | b393d7820ea6f1f41c164300fa950e29a90768ff /subplot | |
parent | a24b6242e6c41dc222f368194cc141c76b36a5e9 (diff) | |
download | vmadm-be53a50f86c3f9dcbc003d2ced9824829ee81f19.tar.gz |
test: make equality check more generic
Sponsored-by: author
Diffstat (limited to 'subplot')
-rw-r--r-- | subplot/vmadm.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/subplot/vmadm.py b/subplot/vmadm.py index 916458f..52233ed 100644 --- a/subplot/vmadm.py +++ b/subplot/vmadm.py @@ -111,7 +111,6 @@ def run_hostname_over_ssh(ctx, config=None, target=None, args=None): def stdout_json_matches(ctx, filename=None): runcmd_get_stdout = globals()["runcmd_get_stdout"] - assert_dict_eq = globals()["assert_dict_eq"] stdout = io.StringIO(runcmd_get_stdout(ctx)) actual = yaml.safe_load(stdout) @@ -123,7 +122,7 @@ def stdout_json_matches(ctx, filename=None): logging.debug(f"actual: {actual}") logging.debug(f"expect: {expected}") - assert_dict_eq(actual, expected) + _assert_equal_objects(actual, expected) def _expand_tilde(o): @@ -135,3 +134,19 @@ def _expand_tilde(o): return [_expand_tilde(value) for value in o] else: return o + + +def _assert_equal_objects(a, b): + assert type(a) == type(b) + if isinstance(a, dict): + for key in a: + assert key in b, f"wanted b to have key {key!r}" + _assert_equal_objects(a[key], b[key]) + elif isinstance(a, list): + assert len(a) == len( + b + ), f"wanted a and b to be of same length ({len(a)} vs {len(b)})" + for i in range(len(a)): + _assert_equal_objects(a[i], b[i]) + else: + assert a == b, f"wanted {a!r} and {b!r} to be equal" |