From b3100f6ce7b17302c03c7c8e411ab5b6c970a875 Mon Sep 17 00:00:00 2001 From: GalaxyGorilla Date: Fri, 22 May 2020 21:18:46 +0000 Subject: tests: Fix JSON diff for nested lists The involved piece of code is supposed to find a 'closest' match for two JSON structures using another JSON diff. However, it can happen that during that new diff the JSON structures are altered (elements from a list are deleted when 'found'). This is in general ok when the deleted element is part of the JSON structure which 'matches', but when it later turns out that some other element of the structure doesn't fit, then the whole structure should be recovered. This is now realized by using a deepcopy for the besaid new JSON diff such that the original is only altered (e.g. deleted) when the diff is clean. Signed-off-by: GalaxyGorilla --- tests/topotests/lib/topotest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/topotests/lib/topotest.py') diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index b0236b01d6..cefb61d198 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -173,7 +173,9 @@ def gen_json_diff_report(d1, d2, exact=False, path="> $", acc=(0, "")): closest_diff = None closest_idx = None for idx1, v1 in zip(range(0, len(d1)), d1): - tmp_diff = gen_json_diff_report(v1, v2, path=add_idx(idx1)) + tmp_v1 = deepcopy(v1) + tmp_v2 = deepcopy(v2) + tmp_diff = gen_json_diff_report(tmp_v1, tmp_v2, path=add_idx(idx1)) if not has_errors(tmp_diff): found_match = True del d1[idx1] -- cgit v1.2.3