/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
1
# (C) 2005 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
1263 by Martin Pool
- clean up imports
17
18
import os
19
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
20
from bzrlib.selftest import TestCaseInTempDir
1263 by Martin Pool
- clean up imports
21
from bzrlib.branch import Branch
22
from bzrlib.commit import commit
1266 by Martin Pool
- fix up testrevision to fetch revisions before marking them merged
23
from bzrlib.fetch import fetch
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
24
from bzrlib.revision import (find_present_ancestors, common_ancestor,
25
                             is_ancestor)
26
from bzrlib.errors import NoSuchRevision
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
27
28
def make_branches():
29
    os.mkdir("branch1")
30
    br1 = Branch("branch1", init=True)
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
31
    
32
    commit(br1, "Commit one", rev_id="a@u-0-0")
33
    commit(br1, "Commit two", rev_id="a@u-0-1")
34
    commit(br1, "Commit three", rev_id="a@u-0-2")
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
35
36
    os.mkdir("branch2")
37
    br2 = Branch("branch2", init=True)
38
    br2.update_revisions(br1)
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
39
    commit(br2, "Commit four", rev_id="b@u-0-3")
40
    commit(br2, "Commit five", rev_id="b@u-0-4")
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
41
    revisions_2 = br2.revision_history()
1263 by Martin Pool
- clean up imports
42
    
1266 by Martin Pool
- fix up testrevision to fetch revisions before marking them merged
43
    fetch(from_branch=br2, to_branch=br1)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
44
    br1.add_pending_merge(revisions_2[4])
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
45
    commit(br1, "Commit six", rev_id="a@u-0-3")
46
    commit(br1, "Commit seven", rev_id="a@u-0-4")
47
    commit(br2, "Commit eight", rev_id="b@u-0-5")
1266 by Martin Pool
- fix up testrevision to fetch revisions before marking them merged
48
    
49
    fetch(from_branch=br2, to_branch=br1)
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
50
    br1.add_pending_merge(br2.revision_history()[5])
51
    commit(br1, "Commit nine", rev_id="a@u-0-5")
1266 by Martin Pool
- fix up testrevision to fetch revisions before marking them merged
52
53
    fetch(from_branch=br1, to_branch=br2)
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
54
    br2.add_pending_merge(br1.revision_history()[4])
55
    commit(br2, "Commit ten", rev_id="b@u-0-6")
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
56
57
    fetch(from_branch=br2, to_branch=br1)
1266 by Martin Pool
- fix up testrevision to fetch revisions before marking them merged
58
    
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
59
    return br1, br2
60
61
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
62
class TestIsAncestor(TestCaseInTempDir):
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
63
    def test_recorded_ancestry(self):
64
        """Test that commit records all ancestors"""
65
        br1, br2 = make_branches()
66
        d = [('a@u-0-0', ['a@u-0-0']),
67
             ('a@u-0-1', ['a@u-0-0', 'a@u-0-1']),
68
             ('a@u-0-2', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2']),
69
             ('b@u-0-3', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3']),
70
             ('b@u-0-4', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-3', 'b@u-0-4']),
71
             ]
72
        for branch in br1, br2:
73
            for rev_id, anc in d:
74
                self.assertEquals(sorted(branch.get_ancestry(rev_id)),
75
                                  sorted(anc))
76
    
77
    
1102 by Martin Pool
- merge test refactoring from robertc
78
    def test_is_ancestor(self):
79
        """Test checking whether a revision is an ancestor of another revision"""
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
80
        br1, br2 = make_branches()
81
        revisions = br1.revision_history()
82
        revisions_2 = br2.revision_history()
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
83
        sources = br1
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
84
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
85
        assert is_ancestor(revisions[0], revisions[0], br1)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
86
        assert is_ancestor(revisions[1], revisions[0], sources)
87
        assert not is_ancestor(revisions[0], revisions[1], sources)
88
        assert is_ancestor(revisions_2[3], revisions[0], sources)
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
89
	# disabled mbp 20050914, doesn't seem to happen anymore
90
        ## self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
91
        ##                  revisions[0], br1)        
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
92
        assert is_ancestor(revisions[3], revisions_2[4], sources)
93
        assert is_ancestor(revisions[3], revisions_2[4], br1)
94
        assert is_ancestor(revisions[3], revisions_2[3], sources)
95
        assert not is_ancestor(revisions[3], revisions_2[3], br1)
96
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
97
98
974.1.52 by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7)
99
class TestIntermediateRevisions(TestCaseInTempDir):
1092.1.42 by Robert Collins
merge from abentley
100
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
101
    def setUp(self):
102
        from bzrlib.commit import commit
974.1.52 by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7)
103
        TestCaseInTempDir.setUp(self)
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
104
        self.br1, self.br2 = make_branches()
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
105
106
        self.br2.commit("Commit eleven", rev_id="b@u-0-7")
107
        self.br2.commit("Commit twelve", rev_id="b@u-0-8")
108
        self.br2.commit("Commit thirtteen", rev_id="b@u-0-9")
109
110
	fetch(from_branch=self.br2, to_branch=self.br1)
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
111
        self.br1.add_pending_merge(self.br2.revision_history()[6])
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
112
        self.br1.commit("Commit fourtten", rev_id="a@u-0-6")
113
114
	fetch(from_branch=self.br1, to_branch=self.br2)
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
115
        self.br2.add_pending_merge(self.br1.revision_history()[6])
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
116
        self.br2.commit("Commit fifteen", rev_id="b@u-0-10")
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
117
118
        from bzrlib.revision import MultipleRevisionSources
119
        self.sources = MultipleRevisionSources(self.br1, self.br2)
120
121
    def intervene(self, ancestor, revision, revision_history=None):
122
        from bzrlib.revision import get_intervening_revisions
123
        return get_intervening_revisions(ancestor,revision, self.sources, 
124
                                         revision_history)
125
1092.1.42 by Robert Collins
merge from abentley
126
    def test_intervene(self):
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
127
        """Find intermediate revisions, without requiring history"""
128
        from bzrlib.errors import NotAncestor, NoSuchRevision
129
        assert len(self.intervene('a@u-0-0', 'a@u-0-0')) == 0
130
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-1'), ['a@u-0-1'])
131
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-2'), 
132
                         ['a@u-0-1', 'a@u-0-2'])
133
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-3'), 
134
                         ['a@u-0-1', 'a@u-0-2', 'b@u-0-3'])
135
        self.assertEqual(self.intervene('b@u-0-3', 'a@u-0-3'), 
136
                         ['b@u-0-4', 'a@u-0-3'])
137
        self.assertEqual(self.intervene('a@u-0-2', 'a@u-0-3', 
138
                                        self.br1.revision_history()), 
139
                         ['a@u-0-3'])
140
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-5', 
141
                                        self.br1.revision_history()), 
142
                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
143
                          'a@u-0-5'])
144
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6', 
145
                         self.br1.revision_history()), 
146
                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
147
                          'b@u-0-6'])
148
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'), 
149
                         ['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4', 
150
                          'b@u-0-5'])
151
        self.assertEqual(self.intervene('b@u-0-3', 'b@u-0-6', 
152
                         self.br2.revision_history()), 
153
                         ['b@u-0-4', 'b@u-0-5', 'b@u-0-6'])
154
        self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10'), 
155
                         ['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
156
        self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10', 
157
                                        self.br2.revision_history()), 
158
                         ['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
159
        self.assertRaises(NotAncestor, self.intervene, 'b@u-0-10', 'b@u-0-6', 
160
                          self.br2.revision_history())
161
        self.assertRaises(NoSuchRevision, self.intervene, 'c@u-0-10', 
162
                          'b@u-0-6', self.br2.revision_history())
163
        self.assertRaises(NoSuchRevision, self.intervene, 'b@u-0-10', 
164
                          'c@u-0-6', self.br2.revision_history())
165
166
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
167
class TestCommonAncestor(TestCaseInTempDir):
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
168
    """Test checking whether a revision is an ancestor of another revision"""
1092.1.39 by Robert Collins
merge from mpool
169
170
    def test_common_ancestor(self):
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
171
        br1, br2 = make_branches()
172
        revisions = br1.revision_history()
173
        revisions_2 = br2.revision_history()
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
174
        sources = br1
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
175
176
        expected_ancestors_list = {revisions[3]:(0, 0), 
177
                                   revisions[2]:(1, 1),
178
                                   revisions_2[4]:(2, 1), 
179
                                   revisions[1]:(3, 2),
180
                                   revisions_2[3]:(4, 2),
181
                                   revisions[0]:(5, 3) }
182
        ancestors_list = find_present_ancestors(revisions[3], sources)
183
        assert len(expected_ancestors_list) == len(ancestors_list)
184
        for key, value in expected_ancestors_list.iteritems():
185
            self.assertEqual(ancestors_list[key], value, 
186
                              "key %r, %r != %r" % (key, ancestors_list[key],
187
                                                    value))
188
189
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
190
                          revisions[0])
191
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
192
                          revisions[1])
193
        self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
194
                          revisions[1])
195
        self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
196
                          revisions[2])
197
        self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
198
                          revisions_2[4])
199
        self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
200
                          revisions_2[4])
201
        self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
202
                          revisions[4])
203
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
204
                          revisions_2[5])
1259 by Martin Pool
- let testrevision be run standalone
205
206
207
if __name__ == '__main__':
208
    import unittest, sys
209
    unittest.main()
210