/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
28
    def assertConsistentParents(self, expected, tree):
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
29
        """Check that the parents found are as expected.
30
31
        This test helper also checks that they are consistent with
32
        the pre-get_parent_ids() api - which is now deprecated.
33
        """
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.
34
        self.assertEqual(expected, tree.get_parent_ids())
35
        if expected == []:
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
36
            self.assertEqual(None,
1908.7.8 by Robert Collins
Merge improved test deprecation helpers, simplifying handling of deprecated WorkingTree function tests.
37
                self.applyDeprecated(symbol_versioning.zero_eleven,
38
                    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.
39
        else:
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
40
            self.assertEqual(expected[0],
1908.7.8 by Robert Collins
Merge improved test deprecation helpers, simplifying handling of deprecated WorkingTree function tests.
41
                self.applyDeprecated(symbol_versioning.zero_eleven,
42
                    tree.last_revision))
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
43
        self.assertEqual(expected[1:],
1908.7.8 by Robert Collins
Merge improved test deprecation helpers, simplifying handling of deprecated WorkingTree function tests.
44
            self.applyDeprecated(symbol_versioning.zero_eleven,
45
                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.
46
47
48
class TestSetParents(TestParents):
1908.5.2 by Robert Collins
Create and test set_parent_trees.
49
50
    def test_set_no_parents(self):
51
        t = self.make_branch_and_tree('.')
52
        t.set_parent_trees([])
53
        self.assertEqual([], t.get_parent_ids())
54
        # now give it a real parent, and then set it to no parents again.
55
        t.commit('first post')
56
        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.
57
        self.assertConsistentParents([], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
58
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.
59
    def test_set_one_ghost_parent_rejects(self):
60
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
61
        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.
62
            t.set_parent_trees, [('missing-revision-id', None)])
63
64
    def test_set_one_ghost_parent_force(self):
65
        t = self.make_branch_and_tree('.')
66
        t.set_parent_trees([('missing-revision-id', None)],
67
            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.
68
        self.assertConsistentParents(['missing-revision-id'], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
69
70
    def test_set_two_parents_one_ghost(self):
71
        t = self.make_branch_and_tree('.')
72
        revision_in_repo = t.commit('first post')
73
        # remove the tree's history
74
        uncommit(t.branch, tree=t)
75
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
76
        t.set_parent_trees([(revision_in_repo, rev_tree),
77
            ('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.
78
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
79
80
    def test_set_three_parents(self):
81
        t = self.make_branch_and_tree('.')
82
        first_revision = t.commit('first post')
83
        uncommit(t.branch, tree=t)
84
        second_revision = t.commit('second post')
85
        uncommit(t.branch, tree=t)
86
        third_revision = t.commit('third post')
87
        uncommit(t.branch, tree=t)
88
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
89
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
90
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
91
        t.set_parent_trees([(first_revision, rev_tree1),
92
            (second_revision, rev_tree2),
93
            (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.
94
        self.assertConsistentParents(
95
            [first_revision, second_revision, third_revision], t)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
96
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
97
    def test_set_no_parents_ids(self):
98
        t = self.make_branch_and_tree('.')
99
        t.set_parent_ids([])
100
        self.assertEqual([], t.get_parent_ids())
101
        # now give it a real parent, and then set it to no parents again.
102
        t.commit('first post')
103
        t.set_parent_ids([])
104
        self.assertConsistentParents([], t)
105
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.
106
    def test_set_one_ghost_parent_ids_rejects(self):
107
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
108
        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.
109
            t.set_parent_ids, ['missing-revision-id'])
110
111
    def test_set_one_ghost_parent_ids_force(self):
112
        t = self.make_branch_and_tree('.')
113
        t.set_parent_ids(['missing-revision-id'],
114
            allow_leftmost_as_ghost=True)
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
115
        self.assertConsistentParents(['missing-revision-id'], t)
116
117
    def test_set_two_parents_one_ghost_ids(self):
118
        t = self.make_branch_and_tree('.')
119
        revision_in_repo = t.commit('first post')
120
        # remove the tree's history
121
        uncommit(t.branch, tree=t)
122
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
123
        t.set_parent_ids([revision_in_repo, 'another-missing'])
124
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
125
126
    def test_set_three_parents_ids(self):
127
        t = self.make_branch_and_tree('.')
128
        first_revision = t.commit('first post')
129
        uncommit(t.branch, tree=t)
130
        second_revision = t.commit('second post')
131
        uncommit(t.branch, tree=t)
132
        third_revision = t.commit('third post')
133
        uncommit(t.branch, tree=t)
134
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
135
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
136
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
137
        t.set_parent_ids([first_revision, second_revision, third_revision])
138
        self.assertConsistentParents(
139
            [first_revision, second_revision, third_revision], t)
140
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
141
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
142
class TestAddParent(TestParents):
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
143
144
    def test_add_first_parent_id(self):
145
        """Test adding the first parent id"""
146
        tree = self.make_branch_and_tree('.')
147
        first_revision = tree.commit('first post')
148
        uncommit(tree.branch, tree=tree)
149
        tree.add_parent_tree_id(first_revision)
150
        self.assertConsistentParents([first_revision], tree)
151
        
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.
152
    def test_add_first_parent_id_ghost_rejects(self):
153
        """Test adding the first parent id - as a ghost"""
154
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
155
        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.
156
            tree.add_parent_tree_id, 'first-revision')
157
        
158
    def test_add_first_parent_id_ghost_force(self):
159
        """Test adding the first parent id - as a ghost"""
160
        tree = self.make_branch_and_tree('.')
161
        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.
162
        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.
163
164
    def test_add_second_parent_id_with_ghost_first(self):
165
        """Test adding the second parent when the first is a ghost."""
166
        tree = self.make_branch_and_tree('.')
167
        tree.add_parent_tree_id('first-revision', allow_leftmost_as_ghost=True)
168
        tree.add_parent_tree_id('second')
169
        self.assertConsistentParents(['first-revision', 'second'], tree)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
170
        
171
    def test_add_second_parent_id(self):
172
        """Test adding the second parent id"""
173
        tree = self.make_branch_and_tree('.')
174
        first_revision = tree.commit('first post')
175
        uncommit(tree.branch, tree=tree)
176
        second_revision = tree.commit('second post')
177
        tree.add_parent_tree_id(first_revision)
178
        self.assertConsistentParents([second_revision, first_revision], tree)
179
        
180
    def test_add_second_parent_id_ghost(self):
181
        """Test adding the second parent id - as a ghost"""
182
        tree = self.make_branch_and_tree('.')
183
        first_revision = tree.commit('first post')
184
        tree.add_parent_tree_id('second')
185
        self.assertConsistentParents([first_revision, 'second'], tree)
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
186
        
187
    def test_add_first_parent_tree(self):
188
        """Test adding the first parent id"""
189
        tree = self.make_branch_and_tree('.')
190
        first_revision = tree.commit('first post')
191
        uncommit(tree.branch, tree=tree)
192
        tree.add_parent_tree((first_revision,
193
            tree.branch.repository.revision_tree(first_revision)))
194
        self.assertConsistentParents([first_revision], tree)
195
        
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.
196
    def test_add_first_parent_tree_ghost_rejects(self):
197
        """Test adding the first parent id - as a ghost"""
198
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
199
        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.
200
            tree.add_parent_tree, ('first-revision', None))
201
        
202
    def test_add_first_parent_tree_ghost_force(self):
203
        """Test adding the first parent id - as a ghost"""
204
        tree = self.make_branch_and_tree('.')
205
        tree.add_parent_tree(('first-revision', None),
206
            allow_leftmost_as_ghost=True)
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
207
        self.assertConsistentParents(['first-revision'], tree)
208
        
209
    def test_add_second_parent_tree(self):
210
        """Test adding the second parent id"""
211
        tree = self.make_branch_and_tree('.')
212
        first_revision = tree.commit('first post')
213
        uncommit(tree.branch, tree=tree)
214
        second_revision = tree.commit('second post')
215
        tree.add_parent_tree((first_revision,
216
            tree.branch.repository.revision_tree(first_revision)))
217
        self.assertConsistentParents([second_revision, first_revision], tree)
218
        
219
    def test_add_second_parent_tree_ghost(self):
220
        """Test adding the second parent id - as a ghost"""
221
        tree = self.make_branch_and_tree('.')
222
        first_revision = tree.commit('first post')
223
        tree.add_parent_tree(('second', None))
224
        self.assertConsistentParents([first_revision, 'second'], tree)