~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testrevision.py

  • Committer: Robert Collins
  • Date: 2005-09-28 05:25:54 UTC
  • mfrom: (1185.1.42)
  • mto: (1092.2.18)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050928052554-beb985505f77ea6a
update symlink branch to integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib.selftest import TestCaseInTempDir, TestCase
18
 
 
 
17
from bzrlib.selftest import TestCaseInTempDir
 
18
from bzrlib.revision import is_ancestor, MultipleRevisionSources
 
19
from bzrlib.revision import combined_graph
19
20
 
20
21
def make_branches():
21
22
    from bzrlib.branch import Branch
22
23
    from bzrlib.commit import commit
23
24
    import os
24
25
    os.mkdir("branch1")
25
 
    br1 = Branch("branch1", init=True)
 
26
    br1 = Branch.initialize("branch1")
26
27
    
27
28
    commit(br1, "Commit one", rev_id="a@u-0-0")
28
29
    commit(br1, "Commit two", rev_id="a@u-0-1")
29
30
    commit(br1, "Commit three", rev_id="a@u-0-2")
30
31
 
31
32
    os.mkdir("branch2")
32
 
    br2 = Branch("branch2", init=True)
 
33
    br2 = Branch.initialize("branch2")
33
34
    br2.update_revisions(br1)
34
35
    commit(br2, "Commit four", rev_id="b@u-0-3")
35
36
    commit(br2, "Commit five", rev_id="b@u-0-4")
48
49
class TestIsAncestor(TestCaseInTempDir):
49
50
    def test_is_ancestor(self):
50
51
        """Test checking whether a revision is an ancestor of another revision"""
51
 
        from bzrlib.revision import is_ancestor, MultipleRevisionSources
52
52
        from bzrlib.errors import NoSuchRevision
53
53
        br1, br2 = make_branches()
54
54
        revisions = br1.revision_history()
128
128
        self.assertRaises(NoSuchRevision, self.intervene, 'b@u-0-10', 
129
129
                          'c@u-0-6', self.br2.revision_history())
130
130
 
131
 
class TestIntermediateRevisions(TestCaseInTempDir):
132
 
 
133
 
    def setUp(self):
134
 
        from bzrlib.commit import commit
135
 
        TestCaseInTempDir.setUp(self)
136
 
        self.br1, self.br2 = make_branches()
137
 
        commit(self.br2, "Commit eleven", rev_id="b@u-0-7")
138
 
        commit(self.br2, "Commit twelve", rev_id="b@u-0-8")
139
 
        commit(self.br2, "Commit thirtteen", rev_id="b@u-0-9")
140
 
        self.br1.add_pending_merge(self.br2.revision_history()[6])
141
 
        commit(self.br1, "Commit fourtten", rev_id="a@u-0-6")
142
 
        self.br2.add_pending_merge(self.br1.revision_history()[6])
143
 
        commit(self.br2, "Commit fifteen", rev_id="b@u-0-10")
144
 
 
145
 
        from bzrlib.revision import MultipleRevisionSources
146
 
        self.sources = MultipleRevisionSources(self.br1, self.br2)
147
 
 
148
 
    def intervene(self, ancestor, revision, revision_history=None):
149
 
        from bzrlib.revision import get_intervening_revisions
150
 
        return get_intervening_revisions(ancestor,revision, self.sources, 
151
 
                                         revision_history)
152
 
 
153
 
    def test_intervene(self):
154
 
        """Find intermediate revisions, without requiring history"""
155
 
        from bzrlib.errors import NotAncestor, NoSuchRevision
156
 
        assert len(self.intervene('a@u-0-0', 'a@u-0-0')) == 0
157
 
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-1'), ['a@u-0-1'])
158
 
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-2'), 
159
 
                         ['a@u-0-1', 'a@u-0-2'])
160
 
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-3'), 
161
 
                         ['a@u-0-1', 'a@u-0-2', 'b@u-0-3'])
162
 
        self.assertEqual(self.intervene('b@u-0-3', 'a@u-0-3'), 
163
 
                         ['b@u-0-4', 'a@u-0-3'])
164
 
        self.assertEqual(self.intervene('a@u-0-2', 'a@u-0-3', 
165
 
                                        self.br1.revision_history()), 
166
 
                         ['a@u-0-3'])
167
 
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-5', 
168
 
                                        self.br1.revision_history()), 
169
 
                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
170
 
                          'a@u-0-5'])
171
 
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6', 
172
 
                         self.br1.revision_history()), 
173
 
                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
174
 
                          'b@u-0-6'])
175
 
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'), 
176
 
                         ['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4', 
177
 
                          'b@u-0-5'])
178
 
        self.assertEqual(self.intervene('b@u-0-3', 'b@u-0-6', 
179
 
                         self.br2.revision_history()), 
180
 
                         ['b@u-0-4', 'b@u-0-5', 'b@u-0-6'])
181
 
        self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10'), 
182
 
                         ['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
183
 
        self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10', 
184
 
                                        self.br2.revision_history()), 
185
 
                         ['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
186
 
        self.assertRaises(NotAncestor, self.intervene, 'b@u-0-10', 'b@u-0-6', 
187
 
                          self.br2.revision_history())
188
 
        self.assertRaises(NoSuchRevision, self.intervene, 'c@u-0-10', 
189
 
                          'b@u-0-6', self.br2.revision_history())
190
 
        self.assertRaises(NoSuchRevision, self.intervene, 'b@u-0-10', 
191
 
                          'c@u-0-6', self.br2.revision_history())
192
 
 
193
131
 
194
132
class TestCommonAncestor(TestCaseInTempDir):
195
133
    """Test checking whether a revision is an ancestor of another revision"""
241
179
        revisions = br1.revision_history()
242
180
        revisions_2 = br2.revision_history()
243
181
        sources = MultipleRevisionSources(br1, br2)
 
182
 
244
183
        expected_ancestors_list = {revisions[3]:(0, 0), 
245
184
                                   revisions[2]:(1, 1),
246
185
                                   revisions_2[4]:(2, 1), 
253
192
            self.assertEqual(ancestors_list[key], value, 
254
193
                              "key %r, %r != %r" % (key, ancestors_list[key],
255
194
                                                    value))
 
195
 
256
196
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
257
197
                          revisions[0])
258
198
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
270
210
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
271
211
                          revisions[4])
272
212
 
273
 
 
274
 
class TestCreateSignedRevision(TestCaseInTempDir):
275
 
 
276
 
    def test_create_signed_revision(self):
277
 
        # create a store
278
 
        # create a revision, sign it, apply to the store.
279
 
        pass
280
 
 
281
 
 
282
 
class TestOperators(TestCase):
283
 
 
284
 
    def test___eq__(self):
285
 
        from bzrlib.revision import Revision, RevisionReference
286
 
        revision1 = Revision("invid", "sha", "revid", 100, "boo", "john", [])
287
 
        revision2 = Revision("invid", "sha", "revid", 100, "boo", "john", [])
288
 
        revision3 = Revision("invid", "sha", "rev2id", 100, "bp", "john", 
289
 
                             [RevisionReference("revid")])
290
 
        self.assertEqual(revision1, revision1)
291
 
        self.assertEqual(revision1, revision2)
292
 
        self.assertNotEqual(revision1, revision3)
293
 
        self.assertEqual(revision2, revision1)
294
 
        self.assertEqual(revision2, revision2)
295
 
        self.assertNotEqual(revision2, revision3)
296
 
        self.assertNotEqual(revision3, revision1)
297
 
        self.assertNotEqual(revision3, revision2)
298
 
        self.assertEqual(revision3, revision3)
299
 
 
300
 
    def test__eq__reference(self):
301
 
        from bzrlib.revision import Revision, RevisionReference
302
 
        ref1 = RevisionReference('revid', '1'*40)
303
 
        ref2 = RevisionReference('revid', '1'*40)
304
 
        ref3 = RevisionReference('revid', '2'*40)
305
 
        ref4 = RevisionReference('revid2', '3'*40)
306
 
        self.assertEqual(ref1, ref1)
307
 
        self.assertEqual(ref1, ref2)
308
 
        self.assertNotEqual(ref1, ref3)
309
 
        self.assertNotEqual(ref1, ref4)
310
 
        self.assertEqual(ref2, ref1)
311
 
        self.assertEqual(ref2, ref2)
312
 
        self.assertNotEqual(ref2, ref3)
313
 
        self.assertNotEqual(ref2, ref4)
314
 
        self.assertNotEqual(ref3, ref1)
315
 
        self.assertNotEqual(ref3, ref2)
316
 
        self.assertEqual(ref3, ref3)
317
 
        self.assertNotEqual(ref3, ref4)
318
 
        self.assertNotEqual(ref4, ref1)
319
 
        self.assertNotEqual(ref4, ref2)
320
 
        self.assertNotEqual(ref4, ref3)
321
 
        self.assertEqual(ref4, ref4)
 
213
    def test_combined(self):
 
214
        """combined_graph
 
215
        Ensure it's not order-sensitive
 
216
        """
 
217
        br1, br2 = make_branches()
 
218
        source = MultipleRevisionSources(br1, br2)
 
219
        combined_1 = combined_graph(br1.last_patch(), br2.last_patch(), source)
 
220
        combined_2 = combined_graph(br2.last_patch(), br1.last_patch(), source)
 
221
        assert combined_1[1] == combined_2[1]
 
222
        assert combined_1[2] == combined_2[2]
 
223
        assert combined_1[3] == combined_2[3]
 
224
        assert combined_1 == combined_2