~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-16 04:47:12 UTC
  • Revision ID: mbp@sourcefrog.net-20050916044711-e5a7bfc6ead3800b
- is_ancestor now works by looking at the Branch's stored ancestry

- some tests related to this

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib.branch import Branch
22
22
from bzrlib.commit import commit
23
23
from bzrlib.fetch import fetch
 
24
from bzrlib.revision import (find_present_ancestors, common_ancestor,
 
25
                             is_ancestor)
 
26
from bzrlib.errors import NoSuchRevision
24
27
 
25
28
def make_branches():
26
29
    os.mkdir("branch1")
50
53
    fetch(from_branch=br1, to_branch=br2)
51
54
    br2.add_pending_merge(br1.revision_history()[4])
52
55
    commit(br2, "Commit ten", rev_id="b@u-0-6")
 
56
 
 
57
    fetch(from_branch=br2, to_branch=br1)
53
58
    
54
59
    return br1, br2
55
60
 
56
61
 
57
62
class TestIsAncestor(TestCaseInTempDir):
 
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
    
58
78
    def test_is_ancestor(self):
59
79
        """Test checking whether a revision is an ancestor of another revision"""
60
 
        from bzrlib.revision import is_ancestor, MultipleRevisionSources
61
 
        from bzrlib.errors import NoSuchRevision
62
80
        br1, br2 = make_branches()
63
81
        revisions = br1.revision_history()
64
82
        revisions_2 = br2.revision_history()
65
 
        sources = MultipleRevisionSources(br1, br2)
 
83
        sources = br1
66
84
 
67
 
        assert is_ancestor(revisions[0], revisions[0], sources)
 
85
        assert is_ancestor(revisions[0], revisions[0], br1)
68
86
        assert is_ancestor(revisions[1], revisions[0], sources)
69
87
        assert not is_ancestor(revisions[0], revisions[1], sources)
70
88
        assert is_ancestor(revisions_2[3], revisions[0], sources)
71
 
        self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
72
 
                          revisions[0], br1)        
 
89
        # disabled mbp 20050914, doesn't seem to happen anymore
 
90
        ## self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
 
91
        ##                  revisions[0], br1)        
73
92
        assert is_ancestor(revisions[3], revisions_2[4], sources)
74
93
        assert is_ancestor(revisions[3], revisions_2[4], br1)
75
94
        assert is_ancestor(revisions[3], revisions_2[3], sources)
76
95
        assert not is_ancestor(revisions[3], revisions_2[3], br1)
77
96
 
 
97
 
 
98
 
78
99
class TestIntermediateRevisions(TestCaseInTempDir):
79
100
 
80
101
    def setUp(self):
81
102
        from bzrlib.commit import commit
82
103
        TestCaseInTempDir.setUp(self)
83
104
        self.br1, self.br2 = make_branches()
84
 
        commit(self.br2, "Commit eleven", rev_id="b@u-0-7")
85
 
        commit(self.br2, "Commit twelve", rev_id="b@u-0-8")
86
 
        commit(self.br2, "Commit thirtteen", rev_id="b@u-0-9")
 
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)
87
111
        self.br1.add_pending_merge(self.br2.revision_history()[6])
88
 
        commit(self.br1, "Commit fourtten", rev_id="a@u-0-6")
 
112
        self.br1.commit("Commit fourtten", rev_id="a@u-0-6")
 
113
 
 
114
        fetch(from_branch=self.br1, to_branch=self.br2)
89
115
        self.br2.add_pending_merge(self.br1.revision_history()[6])
90
 
        commit(self.br2, "Commit fifteen", rev_id="b@u-0-10")
 
116
        self.br2.commit("Commit fifteen", rev_id="b@u-0-10")
91
117
 
92
118
        from bzrlib.revision import MultipleRevisionSources
93
119
        self.sources = MultipleRevisionSources(self.br1, self.br2)
142
168
    """Test checking whether a revision is an ancestor of another revision"""
143
169
 
144
170
    def test_common_ancestor(self):
145
 
        from bzrlib.revision import find_present_ancestors, common_ancestor
146
 
        from bzrlib.revision import MultipleRevisionSources
147
171
        br1, br2 = make_branches()
148
172
        revisions = br1.revision_history()
149
173
        revisions_2 = br2.revision_history()
150
 
        sources = MultipleRevisionSources(br1, br2)
 
174
        sources = br1
151
175
 
152
176
        expected_ancestors_list = {revisions[3]:(0, 0), 
153
177
                                   revisions[2]:(1, 1),