How to use the dictdiffer.utils.get_path 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_get_path(self):
        patch = ('add/delete', '', [('author', 'Bob')])
        self.assertEqual(('author',), get_path(patch))
        patch = ('add/delete', 'authors', [('name', 'Bob')])
        self.assertEqual(('authors', 'name'), get_path(patch))
        patch = ('add/delete', 'foo.bar', [('name', 'Bob')])
        self.assertEqual(('foo', 'bar', 'name'), get_path(patch))
        patch = ('add/delete', ['foo', 1], [('name', 'Bob')])
        self.assertEqual(('foo', 1, 'name'), get_path(patch))

        patch = ('change', 'foo', [('John', 'Bob')])
        self.assertEqual(('foo',), get_path(patch))
        patch = ('change', 'foo.bar', [('John', 'Bob')])
        self.assertEqual(('foo', 'bar'), get_path(patch))
        patch = ('change', ['foo', 'bar'], [('John', 'Bob')])
        self.assertEqual(('foo', 'bar'), get_path(patch))
        patch = ('change', ['foo', 1], [('John', 'Bob')])
        self.assertEqual(('foo', 1), get_path(patch))
github inveniosoftware / dictdiffer / dictdiffer / resolve.py View on Github external
def _find_conflicting_path(self, conflict):
        """Return the shortest path commown to two patches."""
        p1p = get_path(conflict.first_patch)
        p2p = get_path(conflict.second_patch)

        # This returns the shortest path
        return p1p if len(p1p) <= len(p2p) else p2p
github inveniosoftware / dictdiffer / dictdiffer / conflict.py View on Github external
def _is_conflict(self, patch1, patch2):
        """Decide on a conflict between two patches.

        The conditions are:
        1. The paths are identical
        2. On of the paths is the super path of the other

        :param patch1: First patch tuple
        :param patch2: First patch tuple
        """
        path1 = get_path(patch1)
        path2 = get_path(patch2)

        if path1 == path2:
            return True
        elif is_super_path(path1, path2) and patch1[0] == 'remove':
            return True
        elif is_super_path(path2, path1) and patch2[0] == 'remove':
            return True

        return False
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
github inveniosoftware / dictdiffer / dictdiffer / resolve.py View on Github external
def _find_conflicting_path(self, conflict):
        """Return the shortest path commown to two patches."""
        p1p = get_path(conflict.first_patch)
        p2p = get_path(conflict.second_patch)

        # This returns the shortest path
        return p1p if len(p1p) <= len(p2p) else p2p
github inveniosoftware / dictdiffer / dictdiffer / conflict.py View on Github external
def _is_conflict(self, patch1, patch2):
        """Decide on a conflict between two patches.

        The conditions are:
        1. The paths are identical
        2. On of the paths is the super path of the other

        :param patch1: First patch tuple
        :param patch2: First patch tuple
        """
        path1 = get_path(patch1)
        path2 = get_path(patch2)

        if path1 == path2:
            return True
        elif is_super_path(path1, path2) and patch1[0] == 'remove':
            return True
        elif is_super_path(path2, path1) and patch2[0] == 'remove':
            return True

        return False