~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testrevision.py

  • Committer: Robert Collins
  • Date: 2005-10-06 22:15:52 UTC
  • mfrom: (1185.13.2)
  • mto: This revision was merged to the branch mainline in revision 1420.
  • Revision ID: robertc@robertcollins.net-20051006221552-9b15c96fa504e0ad
mergeĀ fromĀ upstream

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
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
74
    # DO NOT FETCH HERE - we WANT a GHOST.
76
75
    #fetch(from_branch=br1, to_branch=br2)
77
 
    br2.working_tree().add_pending_merge(br1.revision_history()[4])
 
76
    br2.add_pending_merge(br1.revision_history()[4])
78
77
    commit(br2, "Commit ten - ghost merge", rev_id="b@u-0-6")
79
78
    
80
79
    return br1, br2
83
82
class TestIsAncestor(TestCaseInTempDir):
84
83
    def test_recorded_ancestry(self):
85
84
        """Test that commit records all ancestors"""
86
 
        br1, br2 = make_branches(self)
 
85
        br1, br2 = make_branches()
87
86
        d = [('a@u-0-0', ['a@u-0-0']),
88
87
             ('a@u-0-1', ['a@u-0-0', 'a@u-0-1']),
89
88
             ('a@u-0-2', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2']),
119
118
    
120
119
    def test_is_ancestor(self):
121
120
        """Test checking whether a revision is an ancestor of another revision"""
122
 
        br1, br2 = make_branches(self)
 
121
        br1, br2 = make_branches()
123
122
        revisions = br1.revision_history()
124
123
        revisions_2 = br2.revision_history()
125
124
        sources = br1
126
125
 
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))
 
126
        assert is_ancestor(revisions[0], revisions[0], br1)
 
127
        assert is_ancestor(revisions[1], revisions[0], sources)
 
128
        assert not is_ancestor(revisions[0], revisions[1], sources)
 
129
        assert is_ancestor(revisions_2[3], revisions[0], sources)
131
130
        # disabled mbp 20050914, doesn't seem to happen anymore
132
131
        ## self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
133
132
        ##                  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))
 
133
        assert is_ancestor(revisions[3], revisions_2[4], sources)
 
134
        assert is_ancestor(revisions[3], revisions_2[4], br1)
 
135
        assert is_ancestor(revisions[3], revisions_2[3], sources)
 
136
        ## assert not is_ancestor(revisions[3], revisions_2[3], br1)
138
137
 
139
138
 
140
139
class TestIntermediateRevisions(TestCaseInTempDir):
142
141
    def setUp(self):
143
142
        from bzrlib.commit import commit
144
143
        TestCaseInTempDir.setUp(self)
145
 
        self.br1, self.br2 = make_branches(self)
 
144
        self.br1, self.br2 = make_branches()
146
145
 
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")
 
146
        self.br2.commit("Commit eleven", rev_id="b@u-0-7")
 
147
        self.br2.commit("Commit twelve", rev_id="b@u-0-8")
 
148
        self.br2.commit("Commit thirtteen", rev_id="b@u-0-9")
150
149
 
151
150
        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")
 
151
        self.br1.add_pending_merge(self.br2.revision_history()[6])
 
152
        self.br1.commit("Commit fourtten", rev_id="a@u-0-6")
154
153
 
155
154
        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")
 
155
        self.br2.add_pending_merge(self.br1.revision_history()[6])
 
156
        self.br2.commit("Commit fifteen", rev_id="b@u-0-10")
158
157
 
159
158
        from bzrlib.revision import MultipleRevisionSources
160
159
        self.sources = MultipleRevisionSources(self.br1, self.br2)
167
166
    def test_intervene(self):
168
167
        """Find intermediate revisions, without requiring history"""
169
168
        from bzrlib.errors import NotAncestor, NoSuchRevision
170
 
        self.assertEquals(len(self.intervene('a@u-0-0', 'a@u-0-0')), 0)
 
169
        assert len(self.intervene('a@u-0-0', 'a@u-0-0')) == 0
171
170
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-1'), ['a@u-0-1'])
172
171
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-2'), 
173
172
                         ['a@u-0-1', 'a@u-0-2'])
182
181
                                        self.br1.revision_history()), 
183
182
                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
184
183
                          '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'])
 
184
        print ("testrevision.py 191 - intervene appears to return b..6 even"
 
185
               "though it is not reachable!")
 
186
#        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6', 
 
187
#                         self.br1.revision_history()), 
 
188
#                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
 
189
#                          'b@u-0-6'])
 
190
#        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'), 
 
191
#                         ['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4', 
 
192
#                          'b@u-0-5'])
192
193
        self.assertEqual(self.intervene('b@u-0-3', 'b@u-0-6', 
193
194
                         self.br2.revision_history()), 
194
195
                         ['b@u-0-4', 'b@u-0-5', 'b@u-0-6'])
211
212
    def test_old_common_ancestor(self):
212
213
        """Pick a resonable merge base using the old functionality"""
213
214
        from bzrlib.revision import old_common_ancestor as common_ancestor
214
 
        br1, br2 = make_branches(self)
 
215
        br1, br2 = make_branches()
215
216
        revisions = br1.revision_history()
216
217
        revisions_2 = br2.revision_history()
217
218
        sources = br1
223
224
                                   revisions_2[3]:(4, 2),
224
225
                                   revisions[0]:(5, 3) }
225
226
        ancestors_list = find_present_ancestors(revisions[3], sources)
226
 
        self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
 
227
        assert len(expected_ancestors_list) == len(ancestors_list)
227
228
        for key, value in expected_ancestors_list.iteritems():
228
229
            self.assertEqual(ancestors_list[key], value, 
229
230
                              "key %r, %r != %r" % (key, ancestors_list[key],
250
251
    def test_common_ancestor(self):
251
252
        """Pick a reasonable merge base"""
252
253
        from bzrlib.revision import common_ancestor
253
 
        br1, br2 = make_branches(self)
 
254
        br1, br2 = make_branches()
254
255
        revisions = br1.revision_history()
255
256
        revisions_2 = br2.revision_history()
256
257
        sources = MultipleRevisionSources(br1, br2)
261
262
                                   revisions_2[3]:(4, 2),
262
263
                                   revisions[0]:(5, 3) }
263
264
        ancestors_list = find_present_ancestors(revisions[3], sources)
264
 
        self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
 
265
        assert len(expected_ancestors_list) == len(ancestors_list)
265
266
        for key, value in expected_ancestors_list.iteritems():
266
267
            self.assertEqual(ancestors_list[key], value, 
267
268
                              "key %r, %r != %r" % (key, ancestors_list[key],
287
288
        """combined_graph
288
289
        Ensure it's not order-sensitive
289
290
        """
290
 
        br1, br2 = make_branches(self)
 
291
        br1, br2 = make_branches()
291
292
        source = MultipleRevisionSources(br1, br2)
292
293
        combined_1 = combined_graph(br1.last_revision(), 
293
294
                                    br2.last_revision(), source)
294
295
        combined_2 = combined_graph(br2.last_revision(),
295
296
                                    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)
 
297
        assert combined_1[1] == combined_2[1]
 
298
        assert combined_1[2] == combined_2[2]
 
299
        assert combined_1[3] == combined_2[3]
 
300
        assert combined_1 == combined_2