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
|
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
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 |
||
17 |
"""Tests for the InterTree.compare() function."""
|
|
18 |
||
|
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
19 |
import os |
20 |
||
|
2255.6.4
by Aaron Bentley
merge from dirstate |
21 |
from bzrlib import errors, tests, workingtree_4 |
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
22 |
from bzrlib.tests.intertree_implementations import TestCaseWithTwoTrees |
23 |
||
24 |
||
25 |
class TestCompare(TestCaseWithTwoTrees): |
|
26 |
||
27 |
def test_compare_empty_trees(self): |
|
28 |
tree1 = self.make_branch_and_tree('1') |
|
29 |
tree2 = self.make_to_branch_and_tree('2') |
|
30 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
31 |
tree2 = self.get_tree_no_parents_no_content(tree2) |
32 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
33 |
d = self.intertree_class(tree1, tree2).compare() |
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
34 |
self.assertEqual([], d.added) |
35 |
self.assertEqual([], d.modified) |
|
36 |
self.assertEqual([], d.removed) |
|
37 |
self.assertEqual([], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
38 |
self.assertEqual([], d.unchanged) |
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
39 |
|
40 |
def test_empty_to_abc_content(self): |
|
41 |
tree1 = self.make_branch_and_tree('1') |
|
42 |
tree2 = self.make_to_branch_and_tree('2') |
|
43 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
44 |
tree2 = self.get_tree_no_parents_abc_content(tree2) |
45 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
46 |
d = self.intertree_class(tree1, tree2).compare() |
47 |
self.assertEqual([('a', 'a-id', 'file'), |
|
48 |
('b', 'b-id', 'directory'), |
|
49 |
('b/c', 'c-id', 'file'), |
|
50 |
], d.added) |
|
51 |
self.assertEqual([], d.modified) |
|
52 |
self.assertEqual([], d.removed) |
|
53 |
self.assertEqual([], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
54 |
self.assertEqual([], d.unchanged) |
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
55 |
|
|
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
56 |
def test_dangling(self): |
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
57 |
# This test depends on the ability for some trees to have a difference
|
58 |
# between a 'versioned present' and 'versioned not present' (aka
|
|
59 |
# dangling) file. In this test there are two trees each with a separate
|
|
60 |
# dangling file, and the dangling files should be considered absent for
|
|
61 |
# the test.
|
|
|
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
62 |
tree1 = self.make_branch_and_tree('1') |
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
63 |
tree2 = self.make_to_branch_and_tree('2') |
|
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
64 |
self.build_tree(['2/a']) |
65 |
tree2.add('a') |
|
66 |
os.unlink('2/a') |
|
67 |
self.build_tree(['1/b']) |
|
68 |
tree1.add('b') |
|
69 |
os.unlink('1/b') |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
70 |
# the conversion to test trees here will leave the trees intact for the
|
71 |
# default intertree, but may perform a commit for other tree types,
|
|
72 |
# which may reduce the validity of the test. XXX: Think about how to
|
|
73 |
# address this.
|
|
74 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
75 |
d = self.intertree_class(tree1, tree2).compare() |
76 |
self.assertEqual([], d.added) |
|
77 |
self.assertEqual([], d.modified) |
|
78 |
self.assertEqual([], d.removed) |
|
79 |
self.assertEqual([], d.renamed) |
|
80 |
self.assertEqual([], d.unchanged) |
|
81 |
||
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
82 |
def test_abc_content_to_empty(self): |
83 |
tree1 = self.make_branch_and_tree('1') |
|
84 |
tree2 = self.make_to_branch_and_tree('2') |
|
85 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
86 |
tree2 = self.get_tree_no_parents_no_content(tree2) |
87 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
88 |
d = self.intertree_class(tree1, tree2).compare() |
89 |
self.assertEqual([], d.added) |
|
90 |
self.assertEqual([], d.modified) |
|
91 |
self.assertEqual([('a', 'a-id', 'file'), |
|
92 |
('b', 'b-id', 'directory'), |
|
93 |
('b/c', 'c-id', 'file'), |
|
94 |
], d.removed) |
|
95 |
self.assertEqual([], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
96 |
self.assertEqual([], d.unchanged) |
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
97 |
|
98 |
def test_content_modification(self): |
|
99 |
tree1 = self.make_branch_and_tree('1') |
|
100 |
tree2 = self.make_to_branch_and_tree('2') |
|
101 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
102 |
tree2 = self.get_tree_no_parents_abc_content_2(tree2) |
103 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
104 |
d = self.intertree_class(tree1, tree2).compare() |
105 |
self.assertEqual([], d.added) |
|
106 |
self.assertEqual([('a', 'a-id', 'file', True, False)], d.modified) |
|
107 |
self.assertEqual([], d.removed) |
|
108 |
self.assertEqual([], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
109 |
self.assertEqual([], d.unchanged) |
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
110 |
|
111 |
def test_meta_modification(self): |
|
112 |
tree1 = self.make_branch_and_tree('1') |
|
113 |
tree2 = self.make_to_branch_and_tree('2') |
|
114 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
115 |
tree2 = self.get_tree_no_parents_abc_content_3(tree2) |
116 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
117 |
d = self.intertree_class(tree1, tree2).compare() |
118 |
self.assertEqual([], d.added) |
|
119 |
self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified) |
|
120 |
self.assertEqual([], d.removed) |
|
121 |
self.assertEqual([], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
122 |
self.assertEqual([], d.unchanged) |
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
123 |
|
124 |
def test_file_rename(self): |
|
125 |
tree1 = self.make_branch_and_tree('1') |
|
126 |
tree2 = self.make_to_branch_and_tree('2') |
|
127 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
128 |
tree2 = self.get_tree_no_parents_abc_content_4(tree2) |
129 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
130 |
d = self.intertree_class(tree1, tree2).compare() |
131 |
self.assertEqual([], d.added) |
|
132 |
self.assertEqual([], d.modified) |
|
133 |
self.assertEqual([], d.removed) |
|
134 |
self.assertEqual([('a', 'd', 'a-id', 'file', False, False)], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
135 |
self.assertEqual([], d.unchanged) |
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
136 |
|
137 |
def test_file_rename_and_modification(self): |
|
138 |
tree1 = self.make_branch_and_tree('1') |
|
139 |
tree2 = self.make_to_branch_and_tree('2') |
|
140 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
141 |
tree2 = self.get_tree_no_parents_abc_content_5(tree2) |
142 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
143 |
d = self.intertree_class(tree1, tree2).compare() |
144 |
self.assertEqual([], d.added) |
|
145 |
self.assertEqual([], d.modified) |
|
146 |
self.assertEqual([], d.removed) |
|
147 |
self.assertEqual([('a', 'd', 'a-id', 'file', True, False)], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
148 |
self.assertEqual([], d.unchanged) |
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
149 |
|
150 |
def test_file_rename_and_meta_modification(self): |
|
151 |
tree1 = self.make_branch_and_tree('1') |
|
152 |
tree2 = self.make_to_branch_and_tree('2') |
|
153 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
154 |
tree2 = self.get_tree_no_parents_abc_content_6(tree2) |
155 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.2
by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare. |
156 |
d = self.intertree_class(tree1, tree2).compare() |
157 |
self.assertEqual([], d.added) |
|
158 |
self.assertEqual([], d.modified) |
|
159 |
self.assertEqual([], d.removed) |
|
160 |
self.assertEqual([('b/c', 'e', 'c-id', 'file', False, True)], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
161 |
self.assertEqual([], d.unchanged) |
|
1852.9.3
by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate. |
162 |
|
163 |
def test_empty_to_abc_content_a_only(self): |
|
164 |
tree1 = self.make_branch_and_tree('1') |
|
165 |
tree2 = self.make_to_branch_and_tree('2') |
|
166 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
167 |
tree2 = self.get_tree_no_parents_abc_content(tree2) |
168 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.3
by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate. |
169 |
d = self.intertree_class(tree1, tree2).compare(specific_files=['a']) |
170 |
self.assertEqual([('a', 'a-id', 'file')], d.added) |
|
171 |
self.assertEqual([], d.modified) |
|
172 |
self.assertEqual([], d.removed) |
|
173 |
self.assertEqual([], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
174 |
self.assertEqual([], d.unchanged) |
|
1852.9.3
by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate. |
175 |
|
176 |
def test_empty_to_abc_content_a_and_c_only(self): |
|
177 |
tree1 = self.make_branch_and_tree('1') |
|
178 |
tree2 = self.make_to_branch_and_tree('2') |
|
179 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
180 |
tree2 = self.get_tree_no_parents_abc_content(tree2) |
181 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.3
by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate. |
182 |
d = self.intertree_class(tree1, tree2).compare( |
183 |
specific_files=['a', 'b/c']) |
|
184 |
self.assertEqual( |
|
185 |
[('a', 'a-id', 'file'), ('b/c', 'c-id', 'file')], |
|
186 |
d.added) |
|
187 |
self.assertEqual([], d.modified) |
|
188 |
self.assertEqual([], d.removed) |
|
189 |
self.assertEqual([], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
190 |
self.assertEqual([], d.unchanged) |
|
1852.9.3
by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate. |
191 |
|
192 |
def test_empty_to_abc_content_b_only(self): |
|
193 |
"""Restricting to a dir matches the children of the dir.""" |
|
194 |
tree1 = self.make_branch_and_tree('1') |
|
195 |
tree2 = self.make_to_branch_and_tree('2') |
|
196 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
197 |
tree2 = self.get_tree_no_parents_abc_content(tree2) |
198 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.3
by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate. |
199 |
d = self.intertree_class(tree1, tree2).compare(specific_files=['b']) |
200 |
self.assertEqual( |
|
201 |
[('b', 'b-id', 'directory'),('b/c', 'c-id', 'file')], |
|
202 |
d.added) |
|
203 |
self.assertEqual([], d.modified) |
|
204 |
self.assertEqual([], d.removed) |
|
205 |
self.assertEqual([], d.renamed) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
206 |
self.assertEqual([], d.unchanged) |
207 |
||
208 |
def test_unchanged_with_renames_and_modifications(self): |
|
209 |
"""want_unchanged should generate a list of unchanged entries.""" |
|
210 |
tree1 = self.make_branch_and_tree('1') |
|
211 |
tree2 = self.make_to_branch_and_tree('2') |
|
212 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
213 |
tree2 = self.get_tree_no_parents_abc_content_5(tree2) |
214 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
215 |
d = self.intertree_class(tree1, tree2).compare(want_unchanged=True) |
216 |
self.assertEqual([], d.added) |
|
217 |
self.assertEqual([], d.modified) |
|
218 |
self.assertEqual([], d.removed) |
|
219 |
self.assertEqual([('a', 'd', 'a-id', 'file', True, False)], d.renamed) |
|
220 |
self.assertEqual( |
|
221 |
[(u'b', 'b-id', 'directory'), (u'b/c', 'c-id', 'file')], |
|
222 |
d.unchanged) |
|
223 |
||
224 |
def test_extra_trees_finds_ids(self): |
|
225 |
"""Ask for a delta between two trees with a path present in a third.""" |
|
226 |
tree1 = self.make_branch_and_tree('1') |
|
227 |
tree2 = self.make_to_branch_and_tree('2') |
|
228 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
229 |
tree2 = self.get_tree_no_parents_abc_content_3(tree2) |
230 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
231 |
d = self.intertree_class(tree1, tree2).compare(specific_files=['b']) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
232 |
# the type of tree-3 does not matter - it is used as a lookup, not
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
233 |
# a dispatch. XXX: For dirstate it does speak to the optimisability of
|
234 |
# the lookup, in merged trees it can be fast-pathed. We probably want
|
|
235 |
# two tests: one as is, and one with it as a pending merge.
|
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
236 |
tree3 = self.make_branch_and_tree('3') |
237 |
tree3 = self.get_tree_no_parents_abc_content_6(tree3) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
238 |
tree3.lock_read() |
239 |
self.addCleanup(tree3.unlock) |
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
240 |
# tree 3 has 'e' which is 'c-id'. Tree 1 has c-id at b/c, and Tree 2
|
241 |
# has c-id at b/c with its exec flag toggled.
|
|
242 |
# without extra_trees, we should get no modifications from this
|
|
243 |
# so do one, to be sure the test is valid.
|
|
244 |
d = self.intertree_class(tree1, tree2).compare( |
|
245 |
specific_files=['e']) |
|
246 |
self.assertEqual([], d.modified) |
|
247 |
# now give it an additional lookup:
|
|
248 |
d = self.intertree_class(tree1, tree2).compare( |
|
249 |
specific_files=['e'], extra_trees=[tree3]) |
|
250 |
self.assertEqual([], d.added) |
|
251 |
self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified) |
|
252 |
self.assertEqual([], d.removed) |
|
253 |
self.assertEqual([], d.renamed) |
|
254 |
self.assertEqual([], d.unchanged) |
|
|
1852.9.5
by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite. |
255 |
|
256 |
def test_require_versioned(self): |
|
257 |
# this does not quite robustly test, as it is passing in missing paths
|
|
258 |
# rather than present-but-not-versioned paths. At the moment there is
|
|
259 |
# no mechanism for managing the test trees (which are readonly) to
|
|
260 |
# get present-but-not-versioned files for trees that can do that.
|
|
261 |
tree1 = self.make_branch_and_tree('1') |
|
262 |
tree2 = self.make_to_branch_and_tree('2') |
|
263 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
264 |
tree2 = self.get_tree_no_parents_abc_content(tree2) |
265 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
1852.9.5
by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite. |
266 |
self.assertRaises(errors.PathsNotVersionedError, |
267 |
self.intertree_class(tree1, tree2).compare, |
|
268 |
specific_files=['d'], |
|
269 |
require_versioned=True) |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
270 |
|
271 |
||
|
2012.1.3
by Aaron Bentley
Always generate tuples (because kind is always used, even when not different) |
272 |
class TestIterChanges(TestCaseWithTwoTrees): |
|
2012.1.1
by Aaron Bentley
Implement change iterator |
273 |
"""Test the comparison iterator""" |
274 |
||
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
275 |
def do_iter_changes(self, tree1, tree2, **extra_args): |
276 |
"""Helper to run _iter_changes from tree1 to tree2. |
|
277 |
|
|
278 |
:param tree1, tree2: The source and target trees. These will be locked
|
|
279 |
automatically.
|
|
280 |
:param **extra_args: Extra args to pass to _iter_changes. This is not
|
|
281 |
inspected by this test helper.
|
|
282 |
"""
|
|
283 |
tree1.lock_read() |
|
284 |
tree2.lock_read() |
|
285 |
try: |
|
286 |
return list(self.intertree_class(tree1, tree2) |
|
287 |
._iter_changes(**extra_args)) |
|
288 |
finally: |
|
289 |
tree1.unlock() |
|
290 |
tree2.unlock() |
|
291 |
||
|
2012.1.1
by Aaron Bentley
Implement change iterator |
292 |
def test_compare_empty_trees(self): |
293 |
tree1 = self.make_branch_and_tree('1') |
|
294 |
tree2 = self.make_to_branch_and_tree('2') |
|
295 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
296 |
tree2 = self.get_tree_no_parents_no_content(tree2) |
297 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
298 |
self.assertEqual([], self.do_iter_changes(tree1, tree2)) |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
299 |
|
|
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
300 |
def added(self, tree, file_id): |
301 |
entry = tree.inventory[file_id] |
|
302 |
path = tree.id2path(file_id) |
|
303 |
return (file_id, path, True, (False, True), (None, entry.parent_id), |
|
304 |
(None, entry.name), (None, entry.kind), |
|
305 |
(None, entry.executable)) |
|
306 |
||
307 |
def deleted(self, tree, file_id): |
|
308 |
entry = tree.inventory[file_id] |
|
309 |
path = tree.id2path(file_id) |
|
310 |
return (file_id, path, True, (True, False), (entry.parent_id, None), |
|
311 |
(entry.name, None), (entry.kind, None), |
|
312 |
(entry.executable, None)) |
|
313 |
||
|
2012.1.1
by Aaron Bentley
Implement change iterator |
314 |
def test_empty_to_abc_content(self): |
315 |
tree1 = self.make_branch_and_tree('1') |
|
316 |
tree2 = self.make_to_branch_and_tree('2') |
|
317 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
318 |
tree2 = self.get_tree_no_parents_abc_content(tree2) |
319 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
2255.2.118
by Robert Collins
Change _iter_changes tests to lock the tested trees - its an iterator interface so implicit locks dont ensure the tree is locked - callers need to lock and thus so do our tests. |
320 |
tree1.lock_read() |
321 |
tree2.lock_read() |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
322 |
expected_results = [ |
323 |
self.added(tree2, 'root-id'), |
|
324 |
self.added(tree2, 'a-id'), |
|
325 |
self.added(tree2, 'b-id'), |
|
326 |
self.added(tree2, 'c-id'), |
|
327 |
self.deleted(tree1, 'empty-root-id')] |
|
328 |
tree1.unlock() |
|
329 |
tree2.unlock() |
|
330 |
self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2)) |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
331 |
|
|
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
332 |
def test_empty_to_abc_content_a_only(self): |
333 |
tree1 = self.make_branch_and_tree('1') |
|
334 |
tree2 = self.make_to_branch_and_tree('2') |
|
335 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
336 |
tree2 = self.get_tree_no_parents_abc_content(tree2) |
337 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
338 |
tree1.lock_read() |
|
339 |
tree2.lock_read() |
|
340 |
self.assertEqual( |
|
341 |
[self.added(tree2, 'a-id')], |
|
342 |
self.do_iter_changes(tree1, tree2, specific_file_ids=['a-id'])) |
|
343 |
tree1.unlock() |
|
344 |
tree2.unlock() |
|
345 |
||
346 |
def test_abc_content_to_empty_to_abc_content_a_only(self): |
|
347 |
tree1 = self.make_branch_and_tree('1') |
|
348 |
tree2 = self.make_to_branch_and_tree('2') |
|
349 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
350 |
tree2 = self.get_tree_no_parents_no_content(tree2) |
|
351 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
352 |
tree1.lock_read() |
|
353 |
tree2.lock_read() |
|
354 |
self.assertEqual( |
|
355 |
[self.deleted(tree1, 'a-id')], |
|
356 |
self.do_iter_changes(tree1, tree2, specific_file_ids=['a-id'])) |
|
357 |
tree1.unlock() |
|
358 |
tree2.unlock() |
|
|
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
359 |
|
360 |
def test_empty_to_abc_content_a_and_c_only(self): |
|
361 |
tree1 = self.make_branch_and_tree('1') |
|
362 |
tree2 = self.make_to_branch_and_tree('2') |
|
363 |
tree1 = self.get_tree_no_parents_no_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
364 |
tree2 = self.get_tree_no_parents_abc_content(tree2) |
365 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
|
2255.2.118
by Robert Collins
Change _iter_changes tests to lock the tested trees - its an iterator interface so implicit locks dont ensure the tree is locked - callers need to lock and thus so do our tests. |
366 |
tree1.lock_read() |
367 |
tree2.lock_read() |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
368 |
expected_result = [self.added(tree2, 'a-id'), self.added(tree2, 'c-id')] |
369 |
tree1.unlock() |
|
370 |
tree2.unlock() |
|
371 |
self.assertEqual(expected_result, |
|
372 |
self.do_iter_changes(tree1, tree2, specific_file_ids=['a-id', 'c-id'])) |
|
|
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
373 |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
374 |
def test_abc_content_to_empty(self): |
|
2012.1.1
by Aaron Bentley
Implement change iterator |
375 |
tree1 = self.make_branch_and_tree('1') |
376 |
tree2 = self.make_to_branch_and_tree('2') |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
377 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
378 |
tree2 = self.get_tree_no_parents_no_content(tree2) |
|
379 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
380 |
tree1.lock_read() |
|
381 |
tree2.lock_read() |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
382 |
def deleted(file_id): |
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
383 |
entry = tree1.inventory[file_id] |
384 |
path = tree1.id2path(file_id) |
|
385 |
return (file_id, path, True, (True, False), |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
386 |
(entry.parent_id, None), |
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
387 |
(entry.name, None), (entry.kind, None), |
|
2012.1.1
by Aaron Bentley
Implement change iterator |
388 |
(entry.executable, None)) |
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
389 |
expected_results = [self.added(tree2, 'empty-root-id'), |
390 |
deleted('root-id'), deleted('a-id'), |
|
391 |
deleted('b-id'), deleted('c-id')] |
|
392 |
tree1.unlock() |
|
393 |
tree2.unlock() |
|
394 |
self.assertEqual( |
|
395 |
expected_results, |
|
396 |
self.do_iter_changes(tree1, tree2)) |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
397 |
|
398 |
def test_content_modification(self): |
|
399 |
tree1 = self.make_branch_and_tree('1') |
|
400 |
tree2 = self.make_to_branch_and_tree('2') |
|
401 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
402 |
tree2 = self.get_tree_no_parents_abc_content_2(tree2) |
403 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
404 |
root_id = tree1.path2id('') |
|
405 |
self.assertEqual([('a-id', 'a', True, (True, True), |
|
406 |
(root_id, root_id), ('a', 'a'), |
|
407 |
('file', 'file'), (False, False))], |
|
408 |
self.do_iter_changes(tree1, tree2)) |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
409 |
|
410 |
def test_meta_modification(self): |
|
411 |
tree1 = self.make_branch_and_tree('1') |
|
412 |
tree2 = self.make_to_branch_and_tree('2') |
|
413 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
414 |
tree2 = self.get_tree_no_parents_abc_content_3(tree2) |
415 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
416 |
self.assertEqual([('c-id', 'b/c', False, (True, True), |
|
417 |
('b-id', 'b-id'), ('c', 'c'), ('file', 'file'), |
|
418 |
(False, True))], |
|
419 |
self.do_iter_changes(tree1, tree2)) |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
420 |
|
421 |
def test_file_rename(self): |
|
422 |
tree1 = self.make_branch_and_tree('1') |
|
423 |
tree2 = self.make_to_branch_and_tree('2') |
|
424 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
425 |
tree2 = self.get_tree_no_parents_abc_content_4(tree2) |
426 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
427 |
root_id = tree1.path2id('') |
|
428 |
self.assertEqual([('a-id', 'd', False, (True, True), |
|
|
2012.1.3
by Aaron Bentley
Always generate tuples (because kind is always used, even when not different) |
429 |
(root_id, root_id), ('a', 'd'), ('file', 'file'), |
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
430 |
(False, False))], |
431 |
self.do_iter_changes(tree1, tree2)) |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
432 |
|
433 |
def test_file_rename_and_modification(self): |
|
434 |
tree1 = self.make_branch_and_tree('1') |
|
435 |
tree2 = self.make_to_branch_and_tree('2') |
|
436 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
437 |
tree2 = self.get_tree_no_parents_abc_content_5(tree2) |
438 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
439 |
root_id = tree1.path2id('') |
|
440 |
self.assertEqual([('a-id', 'd', True, (True, True), |
|
|
2012.1.3
by Aaron Bentley
Always generate tuples (because kind is always used, even when not different) |
441 |
(root_id, root_id), ('a', 'd'), ('file', 'file'), |
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
442 |
(False, False))], |
443 |
self.do_iter_changes(tree1, tree2)) |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
444 |
|
445 |
def test_file_rename_and_meta_modification(self): |
|
446 |
tree1 = self.make_branch_and_tree('1') |
|
447 |
tree2 = self.make_to_branch_and_tree('2') |
|
448 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
449 |
tree2 = self.get_tree_no_parents_abc_content_6(tree2) |
450 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
451 |
root_id = tree1.path2id('') |
|
452 |
self.assertEqual([('c-id', 'e', False, (True, True), |
|
453 |
('b-id', root_id), ('c', 'e'), ('file', 'file'), |
|
454 |
(False, True))], |
|
455 |
self.do_iter_changes(tree1, tree2)) |
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
456 |
|
457 |
def test_unchanged_with_renames_and_modifications(self): |
|
458 |
"""want_unchanged should generate a list of unchanged entries.""" |
|
459 |
tree1 = self.make_branch_and_tree('1') |
|
460 |
tree2 = self.make_to_branch_and_tree('2') |
|
461 |
tree1 = self.get_tree_no_parents_abc_content(tree1) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
462 |
tree2 = self.get_tree_no_parents_abc_content_5(tree2) |
463 |
tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2) |
|
464 |
root_id = tree1.path2id('') |
|
|
2255.2.118
by Robert Collins
Change _iter_changes tests to lock the tested trees - its an iterator interface so implicit locks dont ensure the tree is locked - callers need to lock and thus so do our tests. |
465 |
tree1.lock_read() |
466 |
self.addCleanup(tree1.unlock) |
|
467 |
tree2.lock_read() |
|
468 |
self.addCleanup(tree2.unlock) |
|
|
2012.1.3
by Aaron Bentley
Always generate tuples (because kind is always used, even when not different) |
469 |
def unchanged(file_id): |
470 |
entry = tree1.inventory[file_id] |
|
471 |
parent = entry.parent_id |
|
472 |
name = entry.name |
|
473 |
kind = entry.kind |
|
474 |
executable = entry.executable |
|
|
2255.2.118
by Robert Collins
Change _iter_changes tests to lock the tested trees - its an iterator interface so implicit locks dont ensure the tree is locked - callers need to lock and thus so do our tests. |
475 |
return (file_id, tree1.id2path(file_id), False, (True, True), |
476 |
(parent, parent), (name, name), (kind, kind), |
|
|
2012.1.3
by Aaron Bentley
Always generate tuples (because kind is always used, even when not different) |
477 |
(executable, executable)) |
478 |
self.assertEqual([unchanged(root_id), unchanged('b-id'), |
|
|
2255.2.118
by Robert Collins
Change _iter_changes tests to lock the tested trees - its an iterator interface so implicit locks dont ensure the tree is locked - callers need to lock and thus so do our tests. |
479 |
('a-id', 'd', True, (True, True), |
|
2012.1.3
by Aaron Bentley
Always generate tuples (because kind is always used, even when not different) |
480 |
(root_id, root_id), ('a', 'd'), ('file', 'file'), |
481 |
(False, False)), unchanged('c-id')], |
|
|
2255.6.7
by Aaron Bentley
Merge from dirstate |
482 |
self.do_iter_changes(tree1, tree2, |
483 |
include_unchanged=True)) |
|
|
2100.3.20
by Aaron Bentley
Implement tree comparison for tree references |
484 |
|
485 |
def test_compare_subtrees(self): |
|
486 |
"""want_unchanged should generate a list of unchanged entries.""" |
|
487 |
tree1 = self.make_branch_and_tree('1') |
|
488 |
tree1.set_root_id('root-id') |
|
489 |
subtree1 = self.make_branch_and_tree('1/sub') |
|
490 |
subtree1.set_root_id('subtree-id') |
|
|
2255.6.4
by Aaron Bentley
merge from dirstate |
491 |
try: |
492 |
tree1.add_reference(subtree1) |
|
493 |
except errors.UnsupportedOperation: |
|
494 |
self.assertIsInstance(tree1, workingtree_4.WorkingTree4) |
|
495 |
raise tests.TestSkipped('Tree does not support references') |
|
|
2100.3.20
by Aaron Bentley
Implement tree comparison for tree references |
496 |
|
497 |
tree2 = self.make_to_branch_and_tree('2') |
|
498 |
tree2.set_root_id('root-id') |
|
499 |
subtree2 = self.make_to_branch_and_tree('2/sub') |
|
500 |
subtree2.set_root_id('subtree-id') |
|
501 |
tree2.add_reference(subtree2) |
|
502 |
self.assertEqual([], list(tree2._iter_changes(tree1))) |
|
503 |
subtree1.commit('commit', rev_id='commit-a') |
|
504 |
self.assertEqual([('subtree-id', |
|
505 |
'sub', |
|
506 |
True, |
|
507 |
(True, True), |
|
508 |
('root-id', 'root-id'), |
|
509 |
('sub', 'sub'), |
|
510 |
('tree-reference', 'tree-reference'), |
|
511 |
(False, False))], |
|
512 |
list(tree2._iter_changes(tree1))) |