4def order(source, paths):
5 sort_root =
'' in paths
6 result = _order(source, paths)
8 if sort_root
and isinstance(result, (list, tuple)):
9 result = sorted(result, key=_sort_key)
14def assert_eq(first_source, second_source, paths):
15 assert order(first_source, paths) == order(second_source, paths)
18def _order(source, paths):
19 if isinstance(source, list):
20 return [_order(value, paths)
for value
in source]
21 elif isinstance(source, dict):
22 source_copy = copy.copy(source)
23 for path
in sorted(paths, reverse=
True):
24 head_tail = path.split(
'.', 1)
26 if head
not in source_copy:
28 value = source_copy[head]
29 if len(head_tail) == 1:
30 if isinstance(value, (list, tuple)):
31 source_copy[head] = sorted(value, key=_sort_key)
33 source_copy[head] = _order(value, [head_tail[1]])
40 if isinstance(value, dict):
45 for k, v
in sorted(value.items(), key=_sort_key)
48 if isinstance(value, (list, tuple)):
51 [_sort_key(v)
for v
in sorted(value, key=_sort_key)],
53 return (type(value).__name__, value)