/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1908.5.2 by Robert Collins
Create and test set_parent_trees.
1
# Copyright (C) 2006 by 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
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
17
"""Tests of the parent related functions of WorkingTrees."""
18
1908.5.2 by Robert Collins
Create and test set_parent_trees.
19
import os
20
1908.7.7 by Robert Collins
Deprecated WorkingTree.pending_merges.
21
from bzrlib import errors, symbol_versioning
1908.5.2 by Robert Collins
Create and test set_parent_trees.
22
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
23
from bzrlib.uncommit import uncommit
24
25
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
26
class TestParents(TestCaseWithWorkingTree):
27
1908.7.7 by Robert Collins
Deprecated WorkingTree.pending_merges.
28
    def generate_deprecation(self, a_callable, version_format):
29
        """Generate a deprecation warning string for a_callable."""
30
        name = ('%s.%s.%s' %
31
            (a_callable.im_class.__module__,
32
             a_callable.im_class.__name__,
33
             a_callable.__name__))
34
        return version_format % name
35
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
36
    def assertConsistentParents(self, expected, tree):
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
37
        """Check that the parents found are as expected.
38
39
        This test helper also checks that they are consistent with
40
        the pre-get_parent_ids() api - which is now deprecated.
41
        """
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
42
        self.assertEqual(expected, tree.get_parent_ids())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
43
        last_rev_deprecations = [
1908.7.7 by Robert Collins
Deprecated WorkingTree.pending_merges.
44
            self.generate_deprecation(tree.last_revision, symbol_versioning.zero_eleven)]
45
        pending_merge_deprecations = [
46
            self.generate_deprecation(tree.pending_merges, symbol_versioning.zero_eleven)]
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
47
        if expected == []:
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
48
            self.assertEqual(None,
49
                self.callDeprecated(last_rev_deprecations, tree.last_revision))
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
50
        else:
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
51
            self.assertEqual(expected[0],
52
                self.callDeprecated(last_rev_deprecations, tree.last_revision))
53
        self.assertEqual(expected[1:],
1908.7.7 by Robert Collins
Deprecated WorkingTree.pending_merges.
54
            self.callDeprecated(pending_merge_deprecations, tree.pending_merges))
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
55
56
57
class TestSetParents(TestParents):
1908.5.2 by Robert Collins
Create and test set_parent_trees.
58
59
    def test_set_no_parents(self):
60
        t = self.make_branch_and_tree('.')
61
        t.set_parent_trees([])
62
        self.assertEqual([], t.get_parent_ids())
63
        # now give it a real parent, and then set it to no parents again.
64
        t.commit('first post')
65
        t.set_parent_trees([])
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
66
        self.assertConsistentParents([], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
67
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
68
    def test_set_one_ghost_parent_rejects(self):
69
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
70
        self.assertRaises(errors.GhostRevisionUnusableHere,
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
71
            t.set_parent_trees, [('missing-revision-id', None)])
72
73
    def test_set_one_ghost_parent_force(self):
74
        t = self.make_branch_and_tree('.')
75
        t.set_parent_trees([('missing-revision-id', None)],
76
            allow_leftmost_as_ghost=True)
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
77
        self.assertConsistentParents(['missing-revision-id'], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
78
79
    def test_set_two_parents_one_ghost(self):
80
        t = self.make_branch_and_tree('.')
81
        revision_in_repo = t.commit('first post')
82
        # remove the tree's history
83
        uncommit(t.branch, tree=t)
84
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
85
        t.set_parent_trees([(revision_in_repo, rev_tree),
86
            ('another-missing', None)])
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
87
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
88
89
    def test_set_three_parents(self):
90
        t = self.make_branch_and_tree('.')
91
        first_revision = t.commit('first post')
92
        uncommit(t.branch, tree=t)
93
        second_revision = t.commit('second post')
94
        uncommit(t.branch, tree=t)
95
        third_revision = t.commit('third post')
96
        uncommit(t.branch, tree=t)
97
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
98
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
99
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
100
        t.set_parent_trees([(first_revision, rev_tree1),
101
            (second_revision, rev_tree2),
102
            (third_revision, rev_tree3)])
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
103
        self.assertConsistentParents(
104
            [first_revision, second_revision, third_revision], t)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
105
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
106
    def test_set_no_parents_ids(self):
107
        t = self.make_branch_and_tree('.')
108
        t.set_parent_ids([])
109
        self.assertEqual([], t.get_parent_ids())
110
        # now give it a real parent, and then set it to no parents again.
111
        t.commit('first post')
112
        t.set_parent_ids([])
113
        self.assertConsistentParents([], t)
114
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
115
    def test_set_one_ghost_parent_ids_rejects(self):
116
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
117
        self.assertRaises(errors.GhostRevisionUnusableHere,
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
118
            t.set_parent_ids, ['missing-revision-id'])
119
120
    def test_set_one_ghost_parent_ids_force(self):
121
        t = self.make_branch_and_tree('.')
122
        t.set_parent_ids(['missing-revision-id'],
123
            allow_leftmost_as_ghost=True)
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
124
        self.assertConsistentParents(['missing-revision-id'], t)
125
126
    def test_set_two_parents_one_ghost_ids(self):
127
        t = self.make_branch_and_tree('.')
128
        revision_in_repo = t.commit('first post')
129
        # remove the tree's history
130
        uncommit(t.branch, tree=t)
131
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
132
        t.set_parent_ids([revision_in_repo, 'another-missing'])
133
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
134
135
    def test_set_three_parents_ids(self):
136
        t = self.make_branch_and_tree('.')
137
        first_revision = t.commit('first post')
138
        uncommit(t.branch, tree=t)
139
        second_revision = t.commit('second post')
140
        uncommit(t.branch, tree=t)
141
        third_revision = t.commit('third post')
142
        uncommit(t.branch, tree=t)
143
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
144
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
145
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
146
        t.set_parent_ids([first_revision, second_revision, third_revision])
147
        self.assertConsistentParents(
148
            [first_revision, second_revision, third_revision], t)
149
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
150
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
151
class TestAddParent(TestParents):
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
152
153
    def test_add_first_parent_id(self):
154
        """Test adding the first parent id"""
155
        tree = self.make_branch_and_tree('.')
156
        first_revision = tree.commit('first post')
157
        uncommit(tree.branch, tree=tree)
158
        tree.add_parent_tree_id(first_revision)
159
        self.assertConsistentParents([first_revision], tree)
160
        
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
161
    def test_add_first_parent_id_ghost_rejects(self):
162
        """Test adding the first parent id - as a ghost"""
163
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
164
        self.assertRaises(errors.GhostRevisionUnusableHere,
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
165
            tree.add_parent_tree_id, 'first-revision')
166
        
167
    def test_add_first_parent_id_ghost_force(self):
168
        """Test adding the first parent id - as a ghost"""
169
        tree = self.make_branch_and_tree('.')
170
        tree.add_parent_tree_id('first-revision', allow_leftmost_as_ghost=True)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
171
        self.assertConsistentParents(['first-revision'], tree)
1908.5.13 by Robert Collins
Adding a parent when the first is a ghost already should not require forcing it.
172
173
    def test_add_second_parent_id_with_ghost_first(self):
174
        """Test adding the second parent when the first is a ghost."""
175
        tree = self.make_branch_and_tree('.')
176
        tree.add_parent_tree_id('first-revision', allow_leftmost_as_ghost=True)
177
        tree.add_parent_tree_id('second')
178
        self.assertConsistentParents(['first-revision', 'second'], tree)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
179
        
180
    def test_add_second_parent_id(self):
181
        """Test adding the second parent id"""
182
        tree = self.make_branch_and_tree('.')
183
        first_revision = tree.commit('first post')
184
        uncommit(tree.branch, tree=tree)
185
        second_revision = tree.commit('second post')
186
        tree.add_parent_tree_id(first_revision)
187
        self.assertConsistentParents([second_revision, first_revision], tree)
188
        
189
    def test_add_second_parent_id_ghost(self):
190
        """Test adding the second parent id - as a ghost"""
191
        tree = self.make_branch_and_tree('.')
192
        first_revision = tree.commit('first post')
193
        tree.add_parent_tree_id('second')
194
        self.assertConsistentParents([first_revision, 'second'], tree)
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
195
        
196
    def test_add_first_parent_tree(self):
197
        """Test adding the first parent id"""
198
        tree = self.make_branch_and_tree('.')
199
        first_revision = tree.commit('first post')
200
        uncommit(tree.branch, tree=tree)
201
        tree.add_parent_tree((first_revision,
202
            tree.branch.repository.revision_tree(first_revision)))
203
        self.assertConsistentParents([first_revision], tree)
204
        
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
205
    def test_add_first_parent_tree_ghost_rejects(self):
206
        """Test adding the first parent id - as a ghost"""
207
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
208
        self.assertRaises(errors.GhostRevisionUnusableHere,
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
209
            tree.add_parent_tree, ('first-revision', None))
210
        
211
    def test_add_first_parent_tree_ghost_force(self):
212
        """Test adding the first parent id - as a ghost"""
213
        tree = self.make_branch_and_tree('.')
214
        tree.add_parent_tree(('first-revision', None),
215
            allow_leftmost_as_ghost=True)
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
216
        self.assertConsistentParents(['first-revision'], tree)
217
        
218
    def test_add_second_parent_tree(self):
219
        """Test adding the second parent id"""
220
        tree = self.make_branch_and_tree('.')
221
        first_revision = tree.commit('first post')
222
        uncommit(tree.branch, tree=tree)
223
        second_revision = tree.commit('second post')
224
        tree.add_parent_tree((first_revision,
225
            tree.branch.repository.revision_tree(first_revision)))
226
        self.assertConsistentParents([second_revision, first_revision], tree)
227
        
228
    def test_add_second_parent_tree_ghost(self):
229
        """Test adding the second parent id - as a ghost"""
230
        tree = self.make_branch_and_tree('.')
231
        first_revision = tree.commit('first post')
232
        tree.add_parent_tree(('second', None))
233
        self.assertConsistentParents([first_revision, 'second'], tree)