diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-12 09:29:15 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-12 09:54:09 +0200 |
commit | d848a9587748308421b54ad2e3126f8afc7a3b38 (patch) | |
tree | ff5d07b07f46210090cb729d4dad48e0e8e853c7 /subplot/data.py | |
parent | 755c18a11f87040245964cf411ea8f518b61e0f5 (diff) | |
download | obnam2-d848a9587748308421b54ad2e3126f8afc7a3b38.tar.gz |
test: give better error messages for file manifests differing
This makes it easier to see what the problem is.
Diffstat (limited to 'subplot/data.py')
-rw-r--r-- | subplot/data.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/subplot/data.py b/subplot/data.py index 8817909..9396215 100644 --- a/subplot/data.py +++ b/subplot/data.py @@ -113,3 +113,34 @@ def match_stdout_to_json_file(ctx, filename=None): if stdout[key] != obj[key]: logging.error(f"stdout value for key is not what was exptected") assert_eq(stdout[key], obj[key]) + + +def manifests_match(ctx, expected=None, actual=None): + assert_eq = globals()["assert_eq"] + assert_dict_eq = globals()["assert_dict_eq"] + + logging.debug(f"comparing manifests {expected} and {actual}") + + expected_objs = list(yaml.safe_load_all(open(expected))) + actual_objs = list(yaml.safe_load_all(open(actual))) + + logging.debug(f"there are {len(expected_objs)} and {len(actual_objs)} objects") + + i = 0 + while expected_objs and actual_objs: + e = expected_objs.pop(0) + a = actual_objs.pop(0) + + logging.debug(f"comparing manifest objects at index {i}:") + logging.debug(f" expected: {e}") + logging.debug(f" actual : {a}") + assert_dict_eq(e, a) + + i += 1 + + logging.debug(f"remaining expected objecvts: {expected_objs}") + logging.debug(f"remaining actual objecvts : {actual_objs}") + assert_eq(expected_objs, []) + assert_eq(actual_objs, []) + + logging.debug(f"manifests {expected} and {actual} match") |