How to use the dictdiffer.conflict.Conflict 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_conflict.py View on Github external
def test_init(self):
        p1 = ('add', '', [(0, 0)])
        p2 = ('add', '', [(1, 2)])

        c = Conflict(p1, p2)

        self.assertEqual(c.first_patch, p1)
        self.assertEqual(c.second_patch, p2)
        self.assertEqual(c.take, None)
github inveniosoftware / dictdiffer / tests / test_resolve.py View on Github external
def test_auto_resolve(self):
        r = Resolver({})
        # Sucessful
        p1 = ('add', 'foo', [(0, 0)])
        p2 = ('add', 'foo', [(0, 0)])
        c = Conflict(p1, p2)

        self.assertTrue(r._auto_resolve(c))
        self.assertEqual(c.take, 'f')

        # Fail
        p1 = ('add', 'foo', [(0, 0)])
        p2 = ('add', 'foo', [(0, 1)])
        c = Conflict(p1, p2)

        self.assertFalse(r._auto_resolve(c))
github inveniosoftware / dictdiffer / tests / test_resolve.py View on Github external
p2 = ('add', 'foo', [(0, 0)])
        c = Conflict(p1, p2)

        self.assertEqual(r._find_conflicting_path(c), ('foo',))

        # Same
        p1 = ('add', 'foo', [(0, 0)])
        p2 = ('add', 'foo', [(0, 0)])
        c = Conflict(p1, p2)

        self.assertEqual(r._find_conflicting_path(c), ('foo', 0))

        # B = shortest
        p1 = ('add', 'foo', [(0, 0)])
        p2 = ('delete', '', [('foo', [])])
        c = Conflict(p1, p2)

        self.assertEqual(r._find_conflicting_path(c), ('foo',))
github inveniosoftware / dictdiffer / tests / test_resolve.py View on Github external
def test_auto_resolve(self):
        r = Resolver({})
        # Sucessful
        p1 = ('add', 'foo', [(0, 0)])
        p2 = ('add', 'foo', [(0, 0)])
        c = Conflict(p1, p2)

        self.assertTrue(r._auto_resolve(c))
        self.assertEqual(c.take, 'f')

        # Fail
        p1 = ('add', 'foo', [(0, 0)])
        p2 = ('add', 'foo', [(0, 1)])
        c = Conflict(p1, p2)

        self.assertFalse(r._auto_resolve(c))
github inveniosoftware / dictdiffer / tests / test_conflict.py View on Github external
def test_take_patch(self):
        p1 = ('add', '', [(1, 1)])
        p2 = ('add', '', [(1, -1)])

        c = Conflict(p1, p2)

        self.assertRaises(Exception, c.take_patch)

        c.take = 'f'
        self.assertEqual(c.take_patch(), p1)

        c.take = 's'
        self.assertEqual(c.take_patch(), p2)
github inveniosoftware / dictdiffer / tests / test_resolve.py View on Github external
def test_manual_resolve_conflicts(self):
        p1 = ('add', 'foo', [(0, 0)])
        p2 = ('add', 'foo', [(0, 0)])
        c = Conflict(p1, p2)

        r = Resolver({})
        r.unresolved_conflicts.append(c)

        r.manual_resolve_conflicts(['s'])

        self.assertEqual(c.take, 's')

        # Raise
        r = Resolver({})
        r.unresolved_conflicts.append(c)

        self.assertRaises(UnresolvedConflictsException,
                          r.manual_resolve_conflicts,
                          [])
github inveniosoftware / dictdiffer / tests / test_resolve.py View on Github external
def test_resolve_conflicts(self):
        p1 = ('add', 'foo', [(0, 0)])
        p2 = ('add', 'foo', [(0, 1)])
        c = [Conflict(p1, p2)]

        # KeyError
        r = Resolver({})

        self.assertRaises(UnresolvedConflictsException,
                          r.resolve_conflicts, [p1], [p2], c)

        # Failing action
        r = Resolver({('foo', 0): lambda *args: False})

        self.assertRaises(UnresolvedConflictsException,
                          r.resolve_conflicts, [p1], [p2], c)

        # No further resolution exception
        def no_further(*args):
            raise NoFurtherResolutionException
github inveniosoftware / dictdiffer / tests / test_conflict.py View on Github external
def test_find_conflicts(self):
        p11 = ('add', 'foo.bar', [(0, 0)])
        p12 = ('add', 'foo', [(0, 0)])

        p21 = ('add', 'foo.bar', [(0, 0)])
        p22 = ('add', 'foo', [(1, 0)])

        conflicts = [Conflict(p11, p21)]

        c = ConflictFinder()
        self.assertEqual(repr(c.find_conflicts([p11, p12], [p21, p22])),
                         repr(conflicts))
github inveniosoftware / dictdiffer / dictdiffer / conflict.py View on Github external
def find_conflicts(self, first_patches, second_patches):
        """Find all conflicts between two lists of patches.

        Iterates over the lists of patches, comparing each patch from list
        one to each patch from list two.

        :param first_patches: List of patch tuples
        :param second_patches: List of patch tuples
        """
        self.conflicts = [Conflict(patch1, patch2) for patch1, patch2
                          in itertools.product(first_patches,
                                               second_patches)
                          if self._is_conflict(patch1, patch2)]

        return self.conflicts