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