/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testreweave.py

Split reweave tests into new file and add one more.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Test reweave code.
 
18
 
 
19
Reweave takes two weaves containing a partial view of history and combines
 
20
them into a single weave containing all the information.  This can include 
 
21
 
 
22
 - versions recorded in only one file
 
23
 
 
24
 - versions with different (but not contradictory) lists of parent 
 
25
   revisions
 
26
 
 
27
It is an error if either of these conditions occur:
 
28
 
 
29
 - contradictory ancestry graphs, e.g.
 
30
   - v1 is an ancestor of v2 in one weave, and vice versa in the other
 
31
   - different text for any version 
 
32
"""
 
33
 
 
34
import os
 
35
import sys
 
36
 
 
37
from bzrlib.selftest import TestCaseInTempDir
 
38
from bzrlib.weave import Weave, reweave
 
39
from bzrlib.weavefile import read_weave
 
40
from bzrlib.errors import WeaveParentMismatch
 
41
 
 
42
class TestReweave(TestCaseInTempDir):
 
43
 
 
44
    def test_reweave_add_parents(self):
 
45
        w1 = Weave('w1')
 
46
        w2 = Weave('w2')
 
47
        w1.add('v-1', [], ['line from 1\n'])
 
48
        w2.add('v-2', [], ['line from 2\n'])
 
49
        w1.add('v-3', ['v-1'], ['final line\n'])
 
50
        w2.add('v-3', ['v-2'], ['final line\n'])
 
51
        w3 = reweave(w1, w2)
 
52
        self.assertEqual(sorted(w3.names()),
 
53
                         'v-1 v-2 v-3'.split())
 
54
        self.assertEqualDiff(w3.get_text('v-3'),
 
55
                'final line\n')
 
56
        
 
57
    def build_weave1(self):
 
58
        weave1 = Weave()
 
59
        self.lines1 = ['hello\n']
 
60
        self.lines3 = ['hello\n', 'cruel\n', 'world\n']
 
61
        weave1.add('v1', [], self.lines1)
 
62
        weave1.add('v2', [0], ['hello\n', 'world\n'])
 
63
        weave1.add('v3', [1], self.lines3)
 
64
        return weave1
 
65
        
 
66
    def test_reweave_with_empty(self):
 
67
        wb = Weave()
 
68
        w1 = self.build_weave1()
 
69
        wr = reweave(w1, wb)
 
70
        eq = self.assertEquals
 
71
        eq(sorted(wr.iter_names()), ['v1', 'v2', 'v3'])
 
72
        eq(wr.get_lines('v3'), ['hello\n', 'cruel\n', 'world\n'])
 
73
        self.assertEquals(wr, w1)
 
74
 
 
75
    def test_join_with_ghosts_raises_parent_mismatch(self):
 
76
        wa = self.build_weave1()
 
77
        wb = Weave()
 
78
        wb.add('x1', [], ['line from x1\n'])
 
79
        wb.add('v1', [], ['hello\n'])
 
80
        wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
 
81
        self.assertRaises(WeaveParentMismatch, wa.join, wb)
 
82
 
 
83
    def test_reweave_with_ghosts(self):
 
84
        """Join that inserts parents of an existing revision.
 
85
 
 
86
        This can happen when merging from another branch who
 
87
        knows about revisions the destination does not.  In 
 
88
        this test the second weave knows of an additional parent of 
 
89
        v2.  Any revisions which are in common still have to have the 
 
90
        same text."""
 
91
        w1 = self.build_weave1()
 
92
        wa = w1.copy()
 
93
        wb = Weave()
 
94
        wb.add('x1', [], ['line from x1\n'])
 
95
        wb.add('v1', [], ['hello\n'])
 
96
        wb.add('v2', ['v1', 'x1'], ['hello\n', 'world\n'])
 
97
        wc = reweave(wa, wb)
 
98
        eq = self.assertEquals
 
99
        eq(sorted(wc.iter_names()), ['v1', 'v2', 'v3', 'x1',])
 
100
        eq(wc.get_text('x1'), 'line from x1\n')
 
101
        eq(wc.get_lines('v2'), ['hello\n', 'world\n'])
 
102
        eq(wc.parent_names('v2'), ['v1', 'x1'])
 
103
        w1.reweave(wb)
 
104
        self.assertEquals(wc, w1)