Exemplo n.º 1
0
    def test_unify(self):
        u = Unifier()

        p1 = ("add", "foo", [(0, 0)])
        p2 = ("add", "foo", [(0, 1)])
        c = Conflict(p1, p2)
        c.take = "f"

        u.unify([p1], [p2], [c])

        self.assertEqual(u.unified_patches, [p1])
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    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)
        self.assertFalse(c.handled)
Exemplo n.º 4
0
    def test_build_index(self):
        u = Unifier()

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

        u._build_index([c])

        self.assertEqual(u._index[nested_hash(p1)], c)
        self.assertEqual(u._index[nested_hash(p2)], c)
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
    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

        r = Resolver({('foo', 0): no_further})
        self.assertRaises(UnresolvedConflictsException, r.resolve_conflicts,
                          [p1], [p2], c)

        # Succesful
        r = Resolver({('foo', 0): lambda *args: True})
        r.resolve_conflicts([p1], [p2], c)

        self.assertEqual(r.unresolved_conflicts, [])

        # Succesful auto resolve
        p1 = ('add', 'foo', [(0, 0)])
        p2 = ('add', 'foo', [(0, 0)])
        c = [Conflict(p1, p2)]

        r = Resolver({})
        r.resolve_conflicts([p1], [p2], c)

        self.assertEqual(r.unresolved_conflicts, [])
Exemplo n.º 7
0
    def test_find_conflicting_path(self):
        r = Resolver({})

        # A = shortest
        p1 = ('delete', '', [('foo', [])])
        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', ))
Exemplo n.º 8
0
    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, [])
Exemplo n.º 9
0
    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)