comparison planemo/lib/python3.7/site-packages/schema_salad/tests/matcher.py @ 1:56ad4e20f292 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:32:28 -0400
parents
children
comparison
equal deleted inserted replaced
0:d30785e31577 1:56ad4e20f292
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 import difflib
6 import re
7
8 from schema_salad.utils import json_dumps
9
10
11 class JsonDiffMatcher(object):
12 """Raise AssertionError with a readable JSON diff when not __eq__().
13
14 Used with assert_called_with() so it's possible for a human to see
15 the differences between expected and actual call arguments that
16 include non-trivial data structures.
17 """
18
19 def __init__(self, expected):
20 self.expected = expected
21
22 def __eq__(self, actual):
23 expected_json = json_dumps(self.expected, sort_keys=True, indent=2)
24 actual_json = json_dumps(actual, sort_keys=True, indent=2)
25 if expected_json != actual_json:
26 raise AssertionError(
27 "".join(
28 difflib.context_diff(
29 expected_json.splitlines(1),
30 actual_json.splitlines(1),
31 fromfile="Expected",
32 tofile="Actual",
33 )
34 )
35 )
36 return True
37
38
39 def StripYAMLComments(yml):
40 return re.sub(r"(?ms)^(#.*?\n)*\n*", "", yml)