How to use the dictdiffer.utils.nested_hash function in dictdiffer

To help you get started, we’ve selected a few dictdiffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inveniosoftware / dictdiffer / tests / test_utils.py View on Github external
def test_nested_hash(self):
        # No reasonable way to test this
        nested_hash([1, 2, 3])
        nested_hash((1, 2, 3))
        nested_hash(set([1, 2, 3]))
        nested_hash({'foo': 'bar'})
github inveniosoftware / dictdiffer / tests / test_utils.py View on Github external
def test_nested_hash(self):
        # No reasonable way to test this
        nested_hash([1, 2, 3])
        nested_hash((1, 2, 3))
        nested_hash(set([1, 2, 3]))
        nested_hash({'foo': 'bar'})
github inveniosoftware / dictdiffer / dictdiffer / unify.py View on Github external
def _build_index(self, conflicts):
        """Create a dictionary attribute mapping patches to conflicts.

        Creates a dictionary attribute mapping the tuplefied version of each
        patch to it's containing Conflict object.
        """
        self._index = {}
        for conflict in conflicts:
            self._index[nested_hash(conflict.first_patch)] = conflict
            self._index[nested_hash(conflict.second_patch)] = conflict
github inveniosoftware / dictdiffer / dictdiffer / unify.py View on Github external
def _build_index(self, conflicts):
        """Create a dictionary attribute mapping patches to conflicts.

        Creates a dictionary attribute mapping the tuplefied version of each
        patch to it's containing Conflict object.
        """
        self._index = {}
        for conflict in conflicts:
            self._index[nested_hash(conflict.first_patch)] = conflict
            self._index[nested_hash(conflict.second_patch)] = conflict
github inveniosoftware / dictdiffer / dictdiffer / unify.py View on Github external
def unify(self, first_patches, second_patches, conflicts):
        """Unify two lists of patches into one.

        Takes into account their appearance in the given list of conflicts.

        :param first_patches: list of dictdiffer.diff patches
        :param second_patches: list of dictdiffer.diff patches
        :param conflicts: list of Conflict objects
        """
        self.unified_patches = []
        self._build_index(conflicts)

        sorted_patches = sorted(first_patches + second_patches, key=get_path)

        for patch in sorted_patches:
            conflict = self._index.get(nested_hash(patch))

            # Apply only the patches that were taken as part of conflict
            # resolution.
            if conflict:
                if conflict.take_patch() != patch:
                    continue

            self.unified_patches.append(patch)

        return self.unified_patches