9552: add compute-checksum flag to arvados-cwl-runner
[arvados.git] / sdk / cwl / tests / matcher.py
1 import difflib
2 import json
3
4
5 class JsonDiffMatcher(object):
6     """Raise AssertionError with a readable JSON diff when not __eq__().
7
8     Used with assert_called_with() so it's possible for a human to see
9     the differences between expected and actual call arguments that
10     include non-trivial data structures.
11     """
12     def __init__(self, expected):
13         self.expected = expected
14
15     def __eq__(self, actual):
16         expected_json = json.dumps(self.expected, sort_keys=True, indent=2)
17         actual_json = json.dumps(actual, sort_keys=True, indent=2)
18         if expected_json != actual_json:
19             raise AssertionError("".join(difflib.context_diff(
20                 expected_json.splitlines(1),
21                 actual_json.splitlines(1),
22                 fromfile="Expected", tofile="Actual")))
23         return True