/brz/remove-bazaar

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