/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
1
# (C) 2005 Canonical Ltd
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1263 by Martin Pool
- clean up imports
17
18
import os
19
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
20
from bzrlib.selftest import TestCaseInTempDir
1263 by Martin Pool
- clean up imports
21
from bzrlib.branch import Branch
22
from bzrlib.commit import commit
23
from bzrlib.fetch import Fetcher
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
24
25
def make_branches():
26
    os.mkdir("branch1")
27
    br1 = Branch("branch1", init=True)
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
28
    
29
    commit(br1, "Commit one", rev_id="a@u-0-0")
30
    commit(br1, "Commit two", rev_id="a@u-0-1")
31
    commit(br1, "Commit three", rev_id="a@u-0-2")
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
32
33
    os.mkdir("branch2")
34
    br2 = Branch("branch2", init=True)
35
    br2.update_revisions(br1)
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
36
    commit(br2, "Commit four", rev_id="b@u-0-3")
37
    commit(br2, "Commit five", rev_id="b@u-0-4")
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
38
    revisions_2 = br2.revision_history()
1263 by Martin Pool
- clean up imports
39
    
40
    ## Fetch(from_branch=br2, to_branch=br1)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
41
    br1.add_pending_merge(revisions_2[4])
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
42
    commit(br1, "Commit six", rev_id="a@u-0-3")
43
    commit(br1, "Commit seven", rev_id="a@u-0-4")
44
    commit(br2, "Commit eight", rev_id="b@u-0-5")
45
    br1.add_pending_merge(br2.revision_history()[5])
46
    commit(br1, "Commit nine", rev_id="a@u-0-5")
47
    br2.add_pending_merge(br1.revision_history()[4])
48
    commit(br2, "Commit ten", rev_id="b@u-0-6")
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
49
    return br1, br2
50
51
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
52
class TestIsAncestor(TestCaseInTempDir):
1102 by Martin Pool
- merge test refactoring from robertc
53
    def test_is_ancestor(self):
54
        """Test checking whether a revision is an ancestor of another revision"""
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
55
        from bzrlib.revision import is_ancestor, MultipleRevisionSources
56
        from bzrlib.errors import NoSuchRevision
57
        br1, br2 = make_branches()
58
        revisions = br1.revision_history()
59
        revisions_2 = br2.revision_history()
60
        sources = MultipleRevisionSources(br1, br2)
61
62
        assert is_ancestor(revisions[0], revisions[0], sources)
63
        assert is_ancestor(revisions[1], revisions[0], sources)
64
        assert not is_ancestor(revisions[0], revisions[1], sources)
65
        assert is_ancestor(revisions_2[3], revisions[0], sources)
66
        self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
67
                          revisions[0], br1)        
68
        assert is_ancestor(revisions[3], revisions_2[4], sources)
69
        assert is_ancestor(revisions[3], revisions_2[4], br1)
70
        assert is_ancestor(revisions[3], revisions_2[3], sources)
71
        assert not is_ancestor(revisions[3], revisions_2[3], br1)
72
974.1.52 by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7)
73
class TestIntermediateRevisions(TestCaseInTempDir):
1092.1.42 by Robert Collins
merge from abentley
74
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
75
    def setUp(self):
76
        from bzrlib.commit import commit
974.1.52 by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7)
77
        TestCaseInTempDir.setUp(self)
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
78
        self.br1, self.br2 = make_branches()
79
        commit(self.br2, "Commit eleven", rev_id="b@u-0-7")
80
        commit(self.br2, "Commit twelve", rev_id="b@u-0-8")
81
        commit(self.br2, "Commit thirtteen", rev_id="b@u-0-9")
82
        self.br1.add_pending_merge(self.br2.revision_history()[6])
83
        commit(self.br1, "Commit fourtten", rev_id="a@u-0-6")
84
        self.br2.add_pending_merge(self.br1.revision_history()[6])
85
        commit(self.br2, "Commit fifteen", rev_id="b@u-0-10")
86
87
        from bzrlib.revision import MultipleRevisionSources
88
        self.sources = MultipleRevisionSources(self.br1, self.br2)
89
90
    def intervene(self, ancestor, revision, revision_history=None):
91
        from bzrlib.revision import get_intervening_revisions
92
        return get_intervening_revisions(ancestor,revision, self.sources, 
93
                                         revision_history)
94
1092.1.42 by Robert Collins
merge from abentley
95
    def test_intervene(self):
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
96
        """Find intermediate revisions, without requiring history"""
97
        from bzrlib.errors import NotAncestor, NoSuchRevision
98
        assert len(self.intervene('a@u-0-0', 'a@u-0-0')) == 0
99
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-1'), ['a@u-0-1'])
100
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-2'), 
101
                         ['a@u-0-1', 'a@u-0-2'])
102
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-3'), 
103
                         ['a@u-0-1', 'a@u-0-2', 'b@u-0-3'])
104
        self.assertEqual(self.intervene('b@u-0-3', 'a@u-0-3'), 
105
                         ['b@u-0-4', 'a@u-0-3'])
106
        self.assertEqual(self.intervene('a@u-0-2', 'a@u-0-3', 
107
                                        self.br1.revision_history()), 
108
                         ['a@u-0-3'])
109
        self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-5', 
110
                                        self.br1.revision_history()), 
111
                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
112
                          'a@u-0-5'])
113
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6', 
114
                         self.br1.revision_history()), 
115
                         ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4', 
116
                          'b@u-0-6'])
117
        self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'), 
118
                         ['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4', 
119
                          'b@u-0-5'])
120
        self.assertEqual(self.intervene('b@u-0-3', 'b@u-0-6', 
121
                         self.br2.revision_history()), 
122
                         ['b@u-0-4', 'b@u-0-5', 'b@u-0-6'])
123
        self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10'), 
124
                         ['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
125
        self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10', 
126
                                        self.br2.revision_history()), 
127
                         ['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
128
        self.assertRaises(NotAncestor, self.intervene, 'b@u-0-10', 'b@u-0-6', 
129
                          self.br2.revision_history())
130
        self.assertRaises(NoSuchRevision, self.intervene, 'c@u-0-10', 
131
                          'b@u-0-6', self.br2.revision_history())
132
        self.assertRaises(NoSuchRevision, self.intervene, 'b@u-0-10', 
133
                          'c@u-0-6', self.br2.revision_history())
134
135
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
136
class TestCommonAncestor(TestCaseInTempDir):
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
137
    """Test checking whether a revision is an ancestor of another revision"""
1092.1.39 by Robert Collins
merge from mpool
138
139
    def test_common_ancestor(self):
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
140
        from bzrlib.revision import find_present_ancestors, common_ancestor
141
        from bzrlib.revision import MultipleRevisionSources
142
        br1, br2 = make_branches()
143
        revisions = br1.revision_history()
144
        revisions_2 = br2.revision_history()
145
        sources = MultipleRevisionSources(br1, br2)
146
147
        expected_ancestors_list = {revisions[3]:(0, 0), 
148
                                   revisions[2]:(1, 1),
149
                                   revisions_2[4]:(2, 1), 
150
                                   revisions[1]:(3, 2),
151
                                   revisions_2[3]:(4, 2),
152
                                   revisions[0]:(5, 3) }
153
        ancestors_list = find_present_ancestors(revisions[3], sources)
154
        assert len(expected_ancestors_list) == len(ancestors_list)
155
        for key, value in expected_ancestors_list.iteritems():
156
            self.assertEqual(ancestors_list[key], value, 
157
                              "key %r, %r != %r" % (key, ancestors_list[key],
158
                                                    value))
159
160
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
161
                          revisions[0])
162
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
163
                          revisions[1])
164
        self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
165
                          revisions[1])
166
        self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
167
                          revisions[2])
168
        self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
169
                          revisions_2[4])
170
        self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
171
                          revisions_2[4])
172
        self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
173
                          revisions[4])
174
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
175
                          revisions_2[5])
1259 by Martin Pool
- let testrevision be run standalone
176
177
178
if __name__ == '__main__':
179
    import unittest, sys
180
    unittest.main()
181