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