~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testrevision.py

  • Committer: Martin Pool
  • Date: 2005-09-29 05:06:14 UTC
  • mto: (1185.12.2) (1393.1.12)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: mbp@sourcefrog.net-20050929050614-a41e6f72af36bb4c
- better error on failing to import bzrlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os
19
19
 
20
 
from bzrlib.tests import TestCaseInTempDir
 
20
from bzrlib.selftest import TestCaseInTempDir
21
21
from bzrlib.branch import Branch
22
22
from bzrlib.commit import commit
23
23
from bzrlib.fetch import fetch
26
26
from bzrlib.trace import mutter
27
27
from bzrlib.errors import NoSuchRevision
28
28
 
29
 
# XXX: Make this a method of a merge base case
30
 
def make_branches(self):
 
29
def make_branches():
31
30
    """Create two branches
32
31
 
33
32
    branch 1 has 6 commits, branch 2 has 3 commits
43
42
    b..3   a..3 merges b..4
44
43
    b..4   a..4
45
44
    b..5   a..5 merges b..5
46
 
    b..6 merges a4
 
45
    b..6
47
46
 
48
47
    so A is missing b6 at the start
49
48
    and B is missing a3, a4, a5
63
62
    revisions_2 = br2.revision_history()
64
63
    
65
64
    fetch(from_branch=br2, to_branch=br1)
66
 
    br1.working_tree().add_pending_merge(revisions_2[4])
67
 
    self.assertEquals(revisions_2[4], 'b@u-0-4')
 
65
    br1.add_pending_merge(revisions_2[4])
 
66
    assert revisions_2[4] == 'b@u-0-4'
68
67
    commit(br1, "Commit six", rev_id="a@u-0-3")
69
68
    commit(br1, "Commit seven", rev_id="a@u-0-4")
70
69
    commit(br2, "Commit eight", rev_id="b@u-0-5")
71
70
    
72
71
    fetch(from_branch=br2, to_branch=br1)
73
 
    br1.working_tree().add_pending_merge(br2.revision_history()[5])
 
72
    br1.add_pending_merge(br2.revision_history()[5])
74
73
    commit(br1, "Commit nine", rev_id="a@u-0-5")
75
 
    # DO NOT FETCH HERE - we WANT a GHOST.
 
74
    # disabled - it makes testing fetch too hard,
 
75
    # but can be easily reenabled (without the fetch
 
76
    # when GHOSTS are supported. RBC 20050928
76
77
    #fetch(from_branch=br1, to_branch=br2)
77
 
    br2.working_tree().add_pending_merge(br1.revision_history()[4])
78
 
    commit(br2, "Commit ten - ghost merge", rev_id="b@u-0-6")
 
78
    #br2.add_pending_merge(br1.revision_history()[4])
 
79
    commit(br2, "Commit ten - no merge", rev_id="b@u-0-6")
 
80
 
 
81
    #fetch(from_branch=br2, to_branch=br1)
79
82
    
80
83
    return br1, br2
81
84
 
83
86
class TestIsAncestor(TestCaseInTempDir):
84
87
    def test_recorded_ancestry(self):
85
88
        """Test that commit records all ancestors"""
86
 
        br1, br2 = make_branches(self)
 
89
        br1, br2 = make_branches()
87
90
        d = [('a@u-0-0', ['a@u-0-0']),
88
91
             ('a@u-0-1', ['a@u-0-0', 'a@u-0-1']),
89
92
             ('a@u-0-2', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2']),
119
122
    
120
123
    def test_is_ancestor(self):
121
124
        """Test checking whether a revision is an ancestor of another revision"""
122
 
        br1, br2 = make_branches(self)
 
125
        br1, br2 = make_branches()
123
126
        revisions = br1.revision_history()
124
127
        revisions_2 = br2.revision_history()
125
128
        sources = br1
126
129
 
127
 
        self.assert_(is_ancestor(revisions[0], revisions[0], br1))
128
 
        self.assert_(is_ancestor(revisions[1], revisions[0], sources))
129
 
        self.assert_(not is_ancestor(revisions[0], revisions[1], sources))
130
 
        self.assert_(is_ancestor(revisions_2[3], revisions[0], sources))
 
130
        assert is_ancestor(revisions[0], revisions[0], br1)
 
131
        assert is_ancestor(revisions[1], revisions[0], sources)
 
132
        assert not is_ancestor(revisions[0], revisions[1], sources)
 
133
        assert is_ancestor(revisions_2[3], revisions[0], sources)
131
134
        # disabled mbp 20050914, doesn't seem to happen anymore
132
135
        ## self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
133
136
        ##                  revisions[0], br1)        
134
 
        self.assert_(is_ancestor(revisions[3], revisions_2[4], sources))
135
 
        self.assert_(is_ancestor(revisions[3], revisions_2[4], br1))
136
 
        self.assert_(is_ancestor(revisions[3], revisions_2[3], sources))
137
 
        ## self.assert_(not is_ancestor(revisions[3], revisions_2[3], br1))
 
137
        assert is_ancestor(revisions[3], revisions_2[4], sources)
 
138
        assert is_ancestor(revisions[3], revisions_2[4], br1)
 
139
        assert is_ancestor(revisions[3], revisions_2[3], sources)
 
140
        ## assert not is_ancestor(revisions[3], revisions_2[3], br1)
 
141
 
138
142
 
139
143
 
140
144
class TestIntermediateRevisions(TestCaseInTempDir):
142
146
    def setUp(self):
143
147
        from bzrlib.commit import commit
144
148
        TestCaseInTempDir.setUp(self)
145
 
        self.br1, self.br2 = make_branches(self)
 
149
        self.br1, self.br2 = make_branches()
146
150
 
147
 
        self.br2.working_tree().commit("Commit eleven", rev_id="b@u-0-7")
148
 
        self.br2.working_tree().commit("Commit twelve", rev_id="b@u-0-8")
149
 
        self.br2.working_tree().commit("Commit thirtteen", rev_id="b@u-0-9")
 
151
        self.br2.commit("Commit eleven", rev_id="b@u-0-7")
 
152
        self.br2.commit("Commit twelve", rev_id="b@u-0-8")
 
153
        self.br2.commit("Commit thirtteen", rev_id="b@u-0-9")
150
154
 
151
155
        fetch(from_branch=self.br2, to_branch=self.br1)
152
 
        self.br1.working_tree().add_pending_merge(self.br2.revision_history()[6])
153
 
        self.br1.working_tree().commit("Commit fourtten", rev_id="a@u-0-6")
 
156
        self.br1.add_pending_merge(self.br2.revision_history()[6])
 
157
        self.br1.commit("Commit fourtten", rev_id="a@u-0-6")
154
158
 
155
159
        fetch(from_branch=self.br1, to_branch=self.br2)
156
 
        self.br2.working_tree().add_pending_merge(self.br1.revision_history()[6])
157
 
        self.br2.working_tree().commit("Commit fifteen", rev_id="b@u-0-10")
 
160
        self.br2.add_pending_merge(self.br1.revision_history()[6])
 
161
        self.br2.commit("Commit fifteen", rev_id="b@u-0-10")
158
162
 
159
163
        from bzrlib.revision import MultipleRevisionSources
160
164
        self.sources = MultipleRevisionSources(self.br1, self.br2)
167
171
    def test_intervene(self):
168
172
        """Find intermediate revisions, without requiring history"""
169
173
        from bzrlib.errors import NotAncestor, NoSuchRevision
170
 
        self.assertEquals(len(self.intervene('a@u-0-0', 'a@u-0-0')), 0)
 
174
        assert len(self.intervene('a@u-0-0', 'a@u-0-0')) == 0
171
175
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-1'), ['a@u-0-1'])
172
176
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-2'), 
173
177
                         ['a@u-0-1', 'a@u-0-2'])
182
186
                                        self.br1.revision_history()), 
183
187
                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
184
188
                          'a@u-0-5'])
185
 
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6', 
186
 
                         self.br1.revision_history()), 
187
 
                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
188
 
                          'b@u-0-6'])
189
 
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'), 
190
 
                         ['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4', 
191
 
                          'b@u-0-5'])
 
189
        print ("testrevision.py 191 - intervene appears to return b..6 even"
 
190
               "though it is not reachable!")
 
191
#        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6', 
 
192
#                         self.br1.revision_history()), 
 
193
#                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
 
194
#                          'b@u-0-6'])
 
195
#        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'), 
 
196
#                         ['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4', 
 
197
#                          'b@u-0-5'])
192
198
        self.assertEqual(self.intervene('b@u-0-3', 'b@u-0-6', 
193
199
                         self.br2.revision_history()), 
194
200
                         ['b@u-0-4', 'b@u-0-5', 'b@u-0-6'])
211
217
    def test_old_common_ancestor(self):
212
218
        """Pick a resonable merge base using the old functionality"""
213
219
        from bzrlib.revision import old_common_ancestor as common_ancestor
214
 
        br1, br2 = make_branches(self)
 
220
        br1, br2 = make_branches()
215
221
        revisions = br1.revision_history()
216
222
        revisions_2 = br2.revision_history()
217
223
        sources = br1
223
229
                                   revisions_2[3]:(4, 2),
224
230
                                   revisions[0]:(5, 3) }
225
231
        ancestors_list = find_present_ancestors(revisions[3], sources)
226
 
        self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
 
232
        assert len(expected_ancestors_list) == len(ancestors_list)
227
233
        for key, value in expected_ancestors_list.iteritems():
228
234
            self.assertEqual(ancestors_list[key], value, 
229
235
                              "key %r, %r != %r" % (key, ancestors_list[key],
243
249
                          revisions_2[4])
244
250
        fetch(from_branch=br2, to_branch=br1)
245
251
        self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
246
 
                          revisions[4]) # revisions_2[5] is equally valid
 
252
                          revisions_2[5])
247
253
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
248
254
                          revisions_2[5])
249
255
 
250
256
    def test_common_ancestor(self):
251
257
        """Pick a reasonable merge base"""
252
258
        from bzrlib.revision import common_ancestor
253
 
        br1, br2 = make_branches(self)
 
259
        br1, br2 = make_branches()
254
260
        revisions = br1.revision_history()
255
261
        revisions_2 = br2.revision_history()
256
262
        sources = MultipleRevisionSources(br1, br2)
 
263
 
257
264
        expected_ancestors_list = {revisions[3]:(0, 0), 
258
265
                                   revisions[2]:(1, 1),
259
266
                                   revisions_2[4]:(2, 1), 
261
268
                                   revisions_2[3]:(4, 2),
262
269
                                   revisions[0]:(5, 3) }
263
270
        ancestors_list = find_present_ancestors(revisions[3], sources)
264
 
        self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
 
271
        assert len(expected_ancestors_list) == len(ancestors_list)
265
272
        for key, value in expected_ancestors_list.iteritems():
266
273
            self.assertEqual(ancestors_list[key], value, 
267
274
                              "key %r, %r != %r" % (key, ancestors_list[key],
268
275
                                                    value))
 
276
 
269
277
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
270
278
                          revisions[0])
271
279
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
279
287
        self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
280
288
                          revisions_2[4])
281
289
        self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
282
 
                          revisions[4]) # revisions_2[5] is equally valid
 
290
                          revisions_2[5])
283
291
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
284
 
                          revisions[4]) # revisions_2[5] is equally valid
 
292
                          revisions_2[5])
285
293
 
286
294
    def test_combined(self):
287
295
        """combined_graph
288
296
        Ensure it's not order-sensitive
289
297
        """
290
 
        br1, br2 = make_branches(self)
 
298
        br1, br2 = make_branches()
291
299
        source = MultipleRevisionSources(br1, br2)
292
300
        combined_1 = combined_graph(br1.last_revision(), 
293
301
                                    br2.last_revision(), source)
294
302
        combined_2 = combined_graph(br2.last_revision(),
295
303
                                    br1.last_revision(), source)
296
 
        self.assertEquals(combined_1[1], combined_2[1])
297
 
        self.assertEquals(combined_1[2], combined_2[2])
298
 
        self.assertEquals(combined_1[3], combined_2[3])
299
 
        self.assertEquals(combined_1, combined_2)
 
304
        assert combined_1[1] == combined_2[1]
 
305
        assert combined_1[2] == combined_2[2]
 
306
        assert combined_1[3] == combined_2[3]
 
307
        assert combined_1 == combined_2