bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
1 |
# Copyright (C) 2007 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
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
16 |
|
17 |
"""Tests for WorkingTree.paths2ids.
|
|
18 |
||
19 |
This API probably needs to be exposed as a tree implementation test, but these
|
|
20 |
initial tests are for the specific cases being refactored from
|
|
21 |
find_ids_across_trees.
|
|
22 |
"""
|
|
23 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
24 |
from breezy import errors |
|
6885.5.10
by Jelmer Vernooij
Only run tests for paths2ids against inventory trees. |
25 |
from breezy.bzr.inventorytree import InventoryTree |
|
6846.2.1
by Jelmer Vernooij
Skip a few tests that don't apply to brz-git. |
26 |
from breezy.tests import ( |
27 |
features, |
|
28 |
TestNotApplicable, |
|
29 |
)
|
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
30 |
from breezy.tests.per_workingtree import TestCaseWithWorkingTree |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
31 |
|
32 |
||
|
2255.2.103
by Robert Collins
Document some future tests for paths2ids. |
33 |
# TODO: This needs an additional test: do a merge, then do a
|
34 |
# paths2id(trees=left parent only), and also with (trees=all parents) to check
|
|
35 |
# that only the requested trees are considered - i.e. have an unversioned path
|
|
36 |
# in the unlisted tree, or an extra file that moves into the selected path but
|
|
37 |
# should not be returned
|
|
38 |
||
39 |
# TODO: test that supplying paths with duplication - i.e. foo, foo, foo/bar -
|
|
40 |
# does not result in garbage out.
|
|
41 |
||
|
2255.2.104
by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate. |
42 |
# TODO: Are we meant to raise the precise unversioned paths when some are
|
43 |
# unversioned - if so, test this.
|
|
|
2255.2.103
by Robert Collins
Document some future tests for paths2ids. |
44 |
|
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
45 |
class TestPaths2Ids(TestCaseWithWorkingTree): |
46 |
||
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
47 |
def assertExpectedIds(self, ids, tree, paths, trees=None, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
48 |
require_versioned=True): |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
49 |
"""Run paths2ids for tree, and check the result.""" |
50 |
tree.lock_read() |
|
51 |
if trees: |
|
|
6631.3.1
by Martin
Run 2to3 map fixer and refactor after |
52 |
for t in trees: |
53 |
t.lock_read() |
|
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
54 |
result = tree.paths2ids(paths, trees, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
55 |
require_versioned=require_versioned) |
|
6631.3.1
by Martin
Run 2to3 map fixer and refactor after |
56 |
for t in trees: |
57 |
t.unlock() |
|
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
58 |
else: |
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
59 |
result = tree.paths2ids(paths, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
60 |
require_versioned=require_versioned) |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
61 |
self.assertEqual(set(ids), result) |
62 |
tree.unlock() |
|
63 |
||
|
2255.2.104
by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate. |
64 |
def test_paths_none_result_none(self): |
65 |
tree = self.make_branch_and_tree('tree') |
|
|
6885.5.10
by Jelmer Vernooij
Only run tests for paths2ids against inventory trees. |
66 |
if not isinstance(tree, InventoryTree): |
67 |
raise TestNotApplicable( |
|
68 |
"test not applicable on non-inventory tests") |
|
69 |
||
|
2255.2.104
by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate. |
70 |
tree.lock_read() |
71 |
self.assertEqual(None, tree.paths2ids(None)) |
|
72 |
tree.unlock() |
|
73 |
||
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
74 |
def test_find_single_root(self): |
75 |
tree = self.make_branch_and_tree('tree') |
|
|
6885.5.10
by Jelmer Vernooij
Only run tests for paths2ids against inventory trees. |
76 |
if not isinstance(tree, InventoryTree): |
77 |
raise TestNotApplicable( |
|
78 |
"test not applicable on non-inventory tests") |
|
79 |
||
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
80 |
self.assertExpectedIds([tree.path2id('')], tree, ['']) |
81 |
||
82 |
def test_find_tree_and_clone_roots(self): |
|
83 |
tree = self.make_branch_and_tree('tree') |
|
|
6885.5.10
by Jelmer Vernooij
Only run tests for paths2ids against inventory trees. |
84 |
if not isinstance(tree, InventoryTree): |
85 |
raise TestNotApplicable( |
|
86 |
"test not applicable on non-inventory tests") |
|
87 |
||
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
88 |
clone = tree.controldir.clone('clone').open_workingtree() |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
89 |
clone.lock_tree_write() |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
90 |
clone_root_id = b'new-id' |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
91 |
clone.set_root_id(clone_root_id) |
92 |
tree_root_id = tree.path2id('') |
|
93 |
clone.unlock() |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
94 |
self.assertExpectedIds( |
95 |
[tree_root_id, clone_root_id], tree, [''], [clone]) |
|
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
96 |
|
97 |
def test_find_tree_basis_roots(self): |
|
98 |
tree = self.make_branch_and_tree('tree') |
|
|
6846.2.1
by Jelmer Vernooij
Skip a few tests that don't apply to brz-git. |
99 |
if not tree.supports_setting_file_ids(): |
100 |
raise TestNotApplicable('tree does not support setting file ids') |
|
101 |
||
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
102 |
tree.commit('basis') |
103 |
basis = tree.basis_tree() |
|
104 |
basis_root_id = basis.path2id('') |
|
105 |
tree.lock_tree_write() |
|
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
106 |
tree_root_id = b'new-id' |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
107 |
tree.set_root_id(tree_root_id) |
108 |
tree.unlock() |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
109 |
self.assertExpectedIds( |
110 |
[tree_root_id, basis_root_id], tree, [''], [basis]) |
|
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
111 |
|
112 |
def test_find_children_of_moved_directories(self): |
|
113 |
"""Check the basic nasty corner case that path2ids should handle. |
|
114 |
||
115 |
This is the following situation:
|
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
116 |
basis:
|
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
117 |
/ ROOT
|
118 |
/dir dir
|
|
119 |
/dir/child-moves child-moves
|
|
120 |
/dir/child-stays child-stays
|
|
121 |
/dir/child-goes child-goes
|
|
122 |
||
123 |
current tree:
|
|
124 |
/ ROOT
|
|
125 |
/child-moves child-moves
|
|
126 |
/newdir newdir
|
|
127 |
/newdir/dir dir
|
|
128 |
/newdir/dir/child-stays child-stays
|
|
129 |
/newdir/dir/new-child new-child
|
|
130 |
||
131 |
In english: we move a directory under a directory that was a sibling,
|
|
132 |
and at the same time remove, or move out of the directory, some of its
|
|
133 |
children, and give it a new child previous absent or a sibling.
|
|
134 |
||
135 |
current_tree.path2ids(['newdir'], [basis]) is meant to handle this
|
|
136 |
correctly: that is it should return the ids:
|
|
137 |
newdir because it was provided
|
|
138 |
dir, because its under newdir in current
|
|
139 |
child-moves because its under dir in old
|
|
140 |
child-stays either because its under newdir/dir in current, or under dir in old
|
|
141 |
child-goes because its under dir in old.
|
|
142 |
new-child because its under dir in new
|
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
143 |
|
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
144 |
Symmetrically, current_tree.path2ids(['dir'], [basis]) is meant to show
|
145 |
new-child, even though its not under the path 'dir' in current, because
|
|
146 |
its under a path selected by 'dir' in basis:
|
|
147 |
dir because its selected in basis.
|
|
148 |
child-moves because its under dir in old
|
|
149 |
child-stays either because its under newdir/dir in current, or under dir in old
|
|
150 |
child-goes because its under dir in old.
|
|
151 |
new-child because its under dir in new.
|
|
152 |
"""
|
|
153 |
tree = self.make_branch_and_tree('tree') |
|
|
6885.5.10
by Jelmer Vernooij
Only run tests for paths2ids against inventory trees. |
154 |
if not isinstance(tree, InventoryTree): |
155 |
raise TestNotApplicable( |
|
156 |
"test not applicable on non-inventory tests") |
|
157 |
||
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
158 |
self.build_tree( |
159 |
['tree/dir/', 'tree/dir/child-moves', 'tree/dir/child-stays', |
|
160 |
'tree/dir/child-goes']) |
|
161 |
tree.add(['dir', 'dir/child-moves', 'dir/child-stays', 'dir/child-goes'], |
|
|
6973.14.12
by Jelmer Vernooij
Merge trunk. |
162 |
[b'dir', b'child-moves', b'child-stays', b'child-goes']) |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
163 |
tree.commit('create basis') |
164 |
basis = tree.basis_tree() |
|
|
6809.4.25
by Jelmer Vernooij
Add paths argument to .unversion. |
165 |
tree.unversion(['dir/child-goes']) |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
166 |
tree.rename_one('dir/child-moves', 'child-moves') |
167 |
self.build_tree(['tree/newdir/']) |
|
|
7058.4.1
by Jelmer Vernooij
Fix another 40 tests. |
168 |
tree.add(['newdir'], [b'newdir']) |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
169 |
tree.rename_one('dir/child-stays', 'child-stays') |
170 |
tree.rename_one('dir', 'newdir/dir') |
|
171 |
tree.rename_one('child-stays', 'newdir/dir/child-stays') |
|
172 |
self.build_tree(['tree/newdir/dir/new-child']) |
|
|
7058.4.1
by Jelmer Vernooij
Fix another 40 tests. |
173 |
tree.add(['newdir/dir/new-child'], [b'new-child']) |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
174 |
self.assertExpectedIds( |
|
6973.14.12
by Jelmer Vernooij
Merge trunk. |
175 |
[b'newdir', b'dir', b'child-moves', b'child-stays', b'child-goes', |
176 |
b'new-child'], tree, ['newdir'], [basis]) |
|
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
177 |
self.assertExpectedIds( |
|
6973.14.12
by Jelmer Vernooij
Merge trunk. |
178 |
[b'dir', b'child-moves', b'child-stays', b'child-goes', b'new-child'], |
|
2255.2.100
by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests. |
179 |
tree, ['dir'], [basis]) |
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
180 |
|
181 |
def test_unversioned_one_tree(self): |
|
182 |
tree = self.make_branch_and_tree('tree') |
|
|
6885.5.10
by Jelmer Vernooij
Only run tests for paths2ids against inventory trees. |
183 |
if not isinstance(tree, InventoryTree): |
184 |
raise TestNotApplicable( |
|
185 |
"test not applicable on non-inventory tests") |
|
186 |
||
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
187 |
self.build_tree(['tree/unversioned']) |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
188 |
self.assertExpectedIds([], tree, ['unversioned'], |
189 |
require_versioned=False) |
|
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
190 |
tree.lock_read() |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
191 |
self.assertRaises(errors.PathsNotVersionedError, |
192 |
tree.paths2ids, ['unversioned']) |
|
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
193 |
tree.unlock() |
194 |
||
|
2255.2.104
by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate. |
195 |
def test_unversioned_in_one_of_multiple_trees(self): |
196 |
# in this test, the path is unversioned in only one tree, and thus
|
|
197 |
# should not raise an error: it must be unversioned in *all* trees to
|
|
198 |
# error.
|
|
199 |
tree = self.make_branch_and_tree('tree') |
|
|
6885.5.10
by Jelmer Vernooij
Only run tests for paths2ids against inventory trees. |
200 |
if not isinstance(tree, InventoryTree): |
201 |
raise TestNotApplicable( |
|
202 |
"test not applicable on non-inventory tests") |
|
203 |
||
|
6851.1.1
by Jelmer Vernooij
More foreign branch fixes. |
204 |
if not tree.supports_setting_file_ids(): |
205 |
raise TestNotApplicable('tree does not support setting file ids') |
|
|
2255.2.104
by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate. |
206 |
tree.commit('make basis') |
207 |
basis = tree.basis_tree() |
|
208 |
self.build_tree(['tree/in-one']) |
|
|
6973.14.12
by Jelmer Vernooij
Merge trunk. |
209 |
tree.add(['in-one'], [b'in-one']) |
210 |
self.assertExpectedIds([b'in-one'], tree, ['in-one'], [basis]) |
|
|
2255.2.104
by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate. |
211 |
|
212 |
def test_unversioned_all_of_multiple_trees(self): |
|
213 |
# in this test, the path is unversioned in every tree, and thus
|
|
214 |
# should not raise an error: it must be unversioned in *all* trees to
|
|
215 |
# error.
|
|
216 |
tree = self.make_branch_and_tree('tree') |
|
|
6885.5.10
by Jelmer Vernooij
Only run tests for paths2ids against inventory trees. |
217 |
if not isinstance(tree, InventoryTree): |
218 |
raise TestNotApplicable( |
|
219 |
"test not applicable on non-inventory tests") |
|
220 |
||
|
2255.2.104
by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate. |
221 |
tree.commit('make basis') |
222 |
basis = tree.basis_tree() |
|
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
223 |
self.assertExpectedIds([], tree, ['unversioned'], [basis], |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
224 |
require_versioned=False) |
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
225 |
tree.lock_read() |
226 |
basis.lock_read() |
|
227 |
self.assertRaises(errors.PathsNotVersionedError, tree.paths2ids, |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
228 |
['unversioned'], [basis]) |
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
229 |
self.assertRaises(errors.PathsNotVersionedError, basis.paths2ids, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
230 |
['unversioned'], [tree]) |
|
2255.2.101
by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api. |
231 |
basis.unlock() |
232 |
tree.unlock() |
|
|
6345.1.2
by Martin Packman
Add targetted working tree tests for places that raise PathsNotVersionedError |
233 |
|
234 |
def test_unversioned_non_ascii_one_tree(self): |
|
235 |
self.requireFeature(features.UnicodeFilenameFeature) |
|
236 |
tree = self.make_branch_and_tree('.') |
|
|
6885.5.10
by Jelmer Vernooij
Only run tests for paths2ids against inventory trees. |
237 |
if not isinstance(tree, InventoryTree): |
238 |
raise TestNotApplicable( |
|
239 |
"test not applicable on non-inventory tests") |
|
240 |
||
|
6345.1.2
by Martin Packman
Add targetted working tree tests for places that raise PathsNotVersionedError |
241 |
self.build_tree([u"\xa7"]) |
242 |
self.assertExpectedIds([], tree, [u"\xa7"], require_versioned=False) |
|
243 |
self.addCleanup(tree.lock_read().unlock) |
|
244 |
e = self.assertRaises(errors.PathsNotVersionedError, |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
245 |
tree.paths2ids, [u"\xa7"]) |
|
6345.1.2
by Martin Packman
Add targetted working tree tests for places that raise PathsNotVersionedError |
246 |
self.assertEqual([u"\xa7"], e.paths) |