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