~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:37:53 UTC
  • mfrom: (1092.3.4)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050928053753-68e6e4c0642eccea
merge from symlink branch

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()
180
180
        revisions = br1.revision_history()
181
181
        revisions_2 = br2.revision_history()
182
182
        sources = MultipleRevisionSources(br1, br2)
 
183
 
183
184
        expected_ancestors_list = {revisions[3]:(0, 0), 
184
185
                                   revisions[2]:(1, 1),
185
186
                                   revisions_2[4]:(2, 1), 
192
193
            self.assertEqual(ancestors_list[key], value, 
193
194
                              "key %r, %r != %r" % (key, ancestors_list[key],
194
195
                                                    value))
 
196
 
195
197
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
196
198
                          revisions[0])
197
199
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
209
211
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
210
212
                          revisions[4])
211
213
 
212
 
 
213
 
class TestCreateSignedRevision(TestCaseInTempDir):
214
 
 
215
 
    def test_create_signed_revision(self):
216
 
        # create a store
217
 
        # create a revision, sign it, apply to the store.
218
 
        pass
219
 
 
220
 
 
221
 
class TestOperators(TestCase):
222
 
 
223
 
    def test___eq__(self):
224
 
        from bzrlib.revision import Revision, RevisionReference
225
 
        revision1 = Revision("invid", "sha", "revid", 100, "boo", "john", [])
226
 
        revision2 = Revision("invid", "sha", "revid", 100, "boo", "john", [])
227
 
        revision3 = Revision("invid", "sha", "rev2id", 100, "bp", "john", 
228
 
                             [RevisionReference("revid")])
229
 
        self.assertEqual(revision1, revision1)
230
 
        self.assertEqual(revision1, revision2)
231
 
        self.assertNotEqual(revision1, revision3)
232
 
        self.assertEqual(revision2, revision1)
233
 
        self.assertEqual(revision2, revision2)
234
 
        self.assertNotEqual(revision2, revision3)
235
 
        self.assertNotEqual(revision3, revision1)
236
 
        self.assertNotEqual(revision3, revision2)
237
 
        self.assertEqual(revision3, revision3)
238
 
 
239
 
    def test__eq__reference(self):
240
 
        from bzrlib.revision import Revision, RevisionReference
241
 
        ref1 = RevisionReference('revid', '1'*40)
242
 
        ref2 = RevisionReference('revid', '1'*40)
243
 
        ref3 = RevisionReference('revid', '2'*40)
244
 
        ref4 = RevisionReference('revid2', '3'*40)
245
 
        self.assertEqual(ref1, ref1)
246
 
        self.assertEqual(ref1, ref2)
247
 
        self.assertNotEqual(ref1, ref3)
248
 
        self.assertNotEqual(ref1, ref4)
249
 
        self.assertEqual(ref2, ref1)
250
 
        self.assertEqual(ref2, ref2)
251
 
        self.assertNotEqual(ref2, ref3)
252
 
        self.assertNotEqual(ref2, ref4)
253
 
        self.assertNotEqual(ref3, ref1)
254
 
        self.assertNotEqual(ref3, ref2)
255
 
        self.assertEqual(ref3, ref3)
256
 
        self.assertNotEqual(ref3, ref4)
257
 
        self.assertNotEqual(ref4, ref1)
258
 
        self.assertNotEqual(ref4, ref2)
259
 
        self.assertNotEqual(ref4, ref3)
260
 
        self.assertEqual(ref4, ref4)
 
214
    def test_combined(self):
 
215
        """combined_graph
 
216
        Ensure it's not order-sensitive
 
217
        """
 
218
        br1, br2 = make_branches()
 
219
        source = MultipleRevisionSources(br1, br2)
 
220
        combined_1 = combined_graph(br1.last_patch(), br2.last_patch(), source)
 
221
        combined_2 = combined_graph(br2.last_patch(), br1.last_patch(), source)
 
222
        assert combined_1[1] == combined_2[1]
 
223
        assert combined_1[2] == combined_2[2]
 
224
        assert combined_1[3] == combined_2[3]
 
225
        assert combined_1 == combined_2