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