From d848a9587748308421b54ad2e3126f8afc7a3b38 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 12 Mar 2021 09:29:15 +0200 Subject: test: give better error messages for file manifests differing This makes it easier to see what the problem is. --- obnam.md | 3 ++- subplot/data.py | 31 +++++++++++++++++++++++++++++++ subplot/data.yaml | 3 +++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/obnam.md b/obnam.md index 6521372..96fca9a 100644 --- a/obnam.md +++ b/obnam.md @@ -1258,12 +1258,13 @@ and a running chunk server and a client config based on metadata.yaml and a file live/data.dat containing some random data and symbolink link live/link that points at data.dat +and symbolink link live/broken that points at does-not-exist and a manifest of the directory live in live.yaml when I run obnam --config metadata.yaml backup then backup generation is GEN when I invoke obnam --config metadata.yaml restore rest given a manifest of the directory live restored in rest in rest.yaml -then files live.yaml and rest.yaml match +then manifests live.yaml and rest.yaml match ~~~ ## Set chunk size 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") diff --git a/subplot/data.yaml b/subplot/data.yaml index 0e13abd..64348d6 100644 --- a/subplot/data.yaml +++ b/subplot/data.yaml @@ -36,3 +36,6 @@ - then: "file {filename} is not restored to {restored}" function: file_is_not_restored + +- then: "manifests {expected} and {actual} match" + function: manifests_match -- cgit v1.2.1