def load_test(self, test_dir):
            def _convert_falsy_value_to_none(value):
                return value if value else None

            root = self.load_single(test_dir, 'root.json')
            head = self.load_single(test_dir, 'head.json')
            update = self.load_single(test_dir, 'update.json')
            expected_conflict = _convert_falsy_value_to_none(
                sort_conflicts(
                    list(self.load_single(test_dir,
                                          'expected_conflict.json'))))

            expected_merged = self.load_single(test_dir,
                                               'expected_merged.json')
            return root, head, update, expected_conflict, expected_merged
Beispiel #2
0
def json_merger(root, head, update, merger_operations):

    merger = Merger(
        root=root,
        head=head,
        update=update,
        default_dict_merge_op=merger_operations.default_dict_merge_op,
        default_list_merge_op=merger_operations.default_list_merge_op,
        list_dict_ops=merger_operations.list_dict_ops,
        list_merge_ops=merger_operations.list_merge_ops,
        comparators=merger_operations.comparators,
    )
    conflicts = None
    try:
        merger.merge()
    except MergeError as e:
        conflicts = sort_conflicts(
            [json.loads(conflict.to_json()) for conflict in e.content])

    merged = merger.merged_root

    return merged, conflicts
def inspire_json_merge(root, head, update):
    """
    This function instantiate a ``Merger`` object using a configuration in
    according to the ``source`` value of head and update params.
    Then it run the merger on the three files provided in input.

    Params
        root(dict): the last common parent json of head and update
        head(dict): the last version of a record in INSPIRE
        update(dict): the update coming from outside INSPIRE to merge

    Return
        A tuple containing the resulted merged record in json format and a
        an object containing all generated conflicts.
    """
    configuration = _get_configuration(get_source(head), get_source(update))

    conflicts = None
    merger = Merger(
        root=root,
        head=head,
        update=update,
        default_dict_merge_op=configuration.default_dict_merge_op,
        default_list_merge_op=configuration.default_list_merge_op,
        list_dict_ops=configuration.list_dict_ops,
        list_merge_ops=configuration.list_merge_ops,
        comparators=configuration.comparators,
    )

    try:
        merger.merge()
    except MergeError as e:
        conflicts = sort_conflicts(
            [json.loads(confl.to_json()) for confl in e.content])

    merged = merger.merged_root
    return merged, conflicts