2411: Fix tests to accommodate copyright notices.
[arvados.git] / sdk / cwl / tests / matcher.py
1 import difflib
2 import json
3 import re
4
5
6 class JsonDiffMatcher(object):
7     """Raise AssertionError with a readable JSON diff when not __eq__().
8
9     Used with assert_called_with() so it's possible for a human to see
10     the differences between expected and actual call arguments that
11     include non-trivial data structures.
12     """
13     def __init__(self, expected):
14         self.expected = expected
15
16     def __eq__(self, actual):
17         expected_json = json.dumps(self.expected, sort_keys=True, indent=2)
18         actual_json = json.dumps(actual, sort_keys=True, indent=2)
19         if expected_json != actual_json:
20             raise AssertionError("".join(difflib.context_diff(
21                 expected_json.splitlines(1),
22                 actual_json.splitlines(1),
23                 fromfile="Expected", tofile="Actual")))
24         return True
25
26
27 def StripYAMLComments(yml):
28     return re.sub(r'(?ms)^(#.*?\n)*\n*', '', yml)