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