/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
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)
31
        tree2 = self.get_to_tree_no_parents_no_content(tree2)
32
        d = self.intertree_class(tree1, tree2).compare()
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
33
        self.assertEqual([], d.added)
34
        self.assertEqual([], d.modified)
35
        self.assertEqual([], d.removed)
36
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
37
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
38
39
    def test_empty_to_abc_content(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)
43
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
44
        d = self.intertree_class(tree1, tree2).compare()
45
        self.assertEqual([('a', 'a-id', 'file'),
46
                          ('b', 'b-id', 'directory'),
47
                          ('b/c', 'c-id', 'file'),
48
                         ], d.added)
49
        self.assertEqual([], d.modified)
50
        self.assertEqual([], d.removed)
51
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
52
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
53
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
54
    def test_dangling(self):
55
        tree1 = self.make_branch_and_tree('1')
56
        tree2 = self.make_branch_and_tree('2')
57
        self.build_tree(['2/a'])
58
        tree2.add('a')
59
        os.unlink('2/a')
60
        self.build_tree(['1/b'])
61
        tree1.add('b')
62
        os.unlink('1/b')
63
        d = self.intertree_class(tree1, tree2).compare()
64
        self.assertEqual([], d.added)
65
        self.assertEqual([], d.modified)
66
        self.assertEqual([], d.removed)
67
        self.assertEqual([], d.renamed)
68
        self.assertEqual([], d.unchanged)
69
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
70
    def test_abc_content_to_empty(self):
71
        tree1 = self.make_branch_and_tree('1')
72
        tree2 = self.make_to_branch_and_tree('2')
73
        tree1 = self.get_tree_no_parents_abc_content(tree1)
74
        tree2 = self.get_to_tree_no_parents_no_content(tree2)
75
        d = self.intertree_class(tree1, tree2).compare()
76
        self.assertEqual([], d.added)
77
        self.assertEqual([], d.modified)
78
        self.assertEqual([('a', 'a-id', 'file'),
79
                          ('b', 'b-id', 'directory'),
80
                          ('b/c', 'c-id', 'file'),
81
                         ], d.removed)
82
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
83
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
84
85
    def test_content_modification(self):
86
        tree1 = self.make_branch_and_tree('1')
87
        tree2 = self.make_to_branch_and_tree('2')
88
        tree1 = self.get_tree_no_parents_abc_content(tree1)
89
        tree2 = self.get_to_tree_no_parents_abc_content_2(tree2)
90
        d = self.intertree_class(tree1, tree2).compare()
91
        self.assertEqual([], d.added)
92
        self.assertEqual([('a', 'a-id', 'file', True, False)], d.modified)
93
        self.assertEqual([], d.removed)
94
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
95
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
96
        
97
    def test_meta_modification(self):
98
        tree1 = self.make_branch_and_tree('1')
99
        tree2 = self.make_to_branch_and_tree('2')
100
        tree1 = self.get_tree_no_parents_abc_content(tree1)
101
        tree2 = self.get_to_tree_no_parents_abc_content_3(tree2)
102
        d = self.intertree_class(tree1, tree2).compare()
103
        self.assertEqual([], d.added)
104
        self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
105
        self.assertEqual([], d.removed)
106
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
107
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
108
109
    def test_file_rename(self):
110
        tree1 = self.make_branch_and_tree('1')
111
        tree2 = self.make_to_branch_and_tree('2')
112
        tree1 = self.get_tree_no_parents_abc_content(tree1)
113
        tree2 = self.get_to_tree_no_parents_abc_content_4(tree2)
114
        d = self.intertree_class(tree1, tree2).compare()
115
        self.assertEqual([], d.added)
116
        self.assertEqual([], d.modified)
117
        self.assertEqual([], d.removed)
118
        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=...).
119
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
120
121
    def test_file_rename_and_modification(self):
122
        tree1 = self.make_branch_and_tree('1')
123
        tree2 = self.make_to_branch_and_tree('2')
124
        tree1 = self.get_tree_no_parents_abc_content(tree1)
125
        tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
126
        d = self.intertree_class(tree1, tree2).compare()
127
        self.assertEqual([], d.added)
128
        self.assertEqual([], d.modified)
129
        self.assertEqual([], d.removed)
130
        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=...).
131
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
132
133
    def test_file_rename_and_meta_modification(self):
134
        tree1 = self.make_branch_and_tree('1')
135
        tree2 = self.make_to_branch_and_tree('2')
136
        tree1 = self.get_tree_no_parents_abc_content(tree1)
137
        tree2 = self.get_to_tree_no_parents_abc_content_6(tree2)
138
        d = self.intertree_class(tree1, tree2).compare()
139
        self.assertEqual([], d.added)
140
        self.assertEqual([], d.modified)
141
        self.assertEqual([], d.removed)
142
        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=...).
143
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
144
145
    def test_empty_to_abc_content_a_only(self):
146
        tree1 = self.make_branch_and_tree('1')
147
        tree2 = self.make_to_branch_and_tree('2')
148
        tree1 = self.get_tree_no_parents_no_content(tree1)
149
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
150
        d = self.intertree_class(tree1, tree2).compare(specific_files=['a'])
151
        self.assertEqual([('a', 'a-id', 'file')], d.added)
152
        self.assertEqual([], d.modified)
153
        self.assertEqual([], d.removed)
154
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
155
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
156
157
    def test_empty_to_abc_content_a_and_c_only(self):
158
        tree1 = self.make_branch_and_tree('1')
159
        tree2 = self.make_to_branch_and_tree('2')
160
        tree1 = self.get_tree_no_parents_no_content(tree1)
161
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
162
        d = self.intertree_class(tree1, tree2).compare(
163
            specific_files=['a', 'b/c'])
164
        self.assertEqual(
165
            [('a', 'a-id', 'file'), ('b/c', 'c-id', 'file')],
166
            d.added)
167
        self.assertEqual([], d.modified)
168
        self.assertEqual([], d.removed)
169
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
170
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
171
172
    def test_empty_to_abc_content_b_only(self):
173
        """Restricting to a dir matches the children of the dir."""
174
        tree1 = self.make_branch_and_tree('1')
175
        tree2 = self.make_to_branch_and_tree('2')
176
        tree1 = self.get_tree_no_parents_no_content(tree1)
177
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
178
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
179
        self.assertEqual(
180
            [('b', 'b-id', 'directory'),('b/c', 'c-id', 'file')],
181
            d.added)
182
        self.assertEqual([], d.modified)
183
        self.assertEqual([], d.removed)
184
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
185
        self.assertEqual([], d.unchanged)
186
187
    def test_unchanged_with_renames_and_modifications(self):
188
        """want_unchanged should generate a list of unchanged entries."""
189
        tree1 = self.make_branch_and_tree('1')
190
        tree2 = self.make_to_branch_and_tree('2')
191
        tree1 = self.get_tree_no_parents_abc_content(tree1)
192
        tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
193
        d = self.intertree_class(tree1, tree2).compare(want_unchanged=True)
194
        self.assertEqual([], d.added)
195
        self.assertEqual([], d.modified)
196
        self.assertEqual([], d.removed)
197
        self.assertEqual([('a', 'd', 'a-id', 'file', True, False)], d.renamed)
198
        self.assertEqual(
199
            [(u'b', 'b-id', 'directory'), (u'b/c', 'c-id', 'file')],
200
            d.unchanged)
201
202
    def test_extra_trees_finds_ids(self):
203
        """Ask for a delta between two trees with a path present in a third."""
204
        tree1 = self.make_branch_and_tree('1')
205
        tree2 = self.make_to_branch_and_tree('2')
206
        tree1 = self.get_tree_no_parents_abc_content(tree1)
207
        tree2 = self.get_to_tree_no_parents_abc_content_3(tree2)
208
        # the type of tree-3 does not matter - it is used as a lookup, not
209
        # a dispatch
210
        tree3 = self.make_branch_and_tree('3')
211
        tree3 = self.get_tree_no_parents_abc_content_6(tree3)
212
        # tree 3 has 'e' which is 'c-id'. Tree 1 has c-id at b/c, and Tree 2
213
        # has c-id at b/c with its exec flag toggled.
214
        # without extra_trees, we should get no modifications from this
215
        # so do one, to be sure the test is valid.
216
        d = self.intertree_class(tree1, tree2).compare(
217
            specific_files=['e'])
218
        self.assertEqual([], d.modified)
219
        # now give it an additional lookup:
220
        d = self.intertree_class(tree1, tree2).compare(
221
            specific_files=['e'], extra_trees=[tree3])
222
        self.assertEqual([], d.added)
223
        self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
224
        self.assertEqual([], d.removed)
225
        self.assertEqual([], d.renamed)
226
        self.assertEqual([], d.unchanged)
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
227
228
    def test_require_versioned(self):
229
        # this does not quite robustly test, as it is passing in missing paths
230
        # rather than present-but-not-versioned paths. At the moment there is
231
        # no mechanism for managing the test trees (which are readonly) to 
232
        # get present-but-not-versioned files for trees that can do that.
233
        tree1 = self.make_branch_and_tree('1')
234
        tree2 = self.make_to_branch_and_tree('2')
235
        tree1 = self.get_tree_no_parents_no_content(tree1)
236
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
237
        self.assertRaises(errors.PathsNotVersionedError, 
238
            self.intertree_class(tree1, tree2).compare,
239
            specific_files=['d'],
240
            require_versioned=True)
2012.1.1 by Aaron Bentley
Implement change iterator
241
242
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
243
class TestIterChanges(TestCaseWithTwoTrees):
2012.1.1 by Aaron Bentley
Implement change iterator
244
    """Test the comparison iterator"""
245
246
    def test_compare_empty_trees(self):
247
        tree1 = self.make_branch_and_tree('1')
248
        tree2 = self.make_to_branch_and_tree('2')
249
        tree1 = self.get_tree_no_parents_no_content(tree1)
250
        tree2 = self.get_to_tree_no_parents_no_content(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.
251
        tree1.lock_read()
252
        self.addCleanup(tree1.unlock)
253
        tree2.lock_read()
254
        self.addCleanup(tree2.unlock)
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
255
        self.assertEqual([], list(tree2._iter_changes(tree1)))
2012.1.1 by Aaron Bentley
Implement change iterator
256
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
257
    def added(self, tree, file_id):
258
        entry = tree.inventory[file_id]
259
        path = tree.id2path(file_id)
260
        return (file_id, path, True, (False, True), (None, entry.parent_id),
261
                (None, entry.name), (None, entry.kind), 
262
                (None, entry.executable))
263
264
    def deleted(self, tree, file_id):
265
        entry = tree.inventory[file_id]
266
        path = tree.id2path(file_id)
267
        return (file_id, path, True, (True, False), (entry.parent_id, None),
268
                (entry.name, None), (entry.kind, None), 
269
                (entry.executable, None))
270
2012.1.1 by Aaron Bentley
Implement change iterator
271
    def test_empty_to_abc_content(self):
272
        tree1 = self.make_branch_and_tree('1')
273
        tree2 = self.make_to_branch_and_tree('2')
274
        tree1 = self.get_tree_no_parents_no_content(tree1)
275
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
276
            
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.
277
        tree1.lock_read()
278
        self.addCleanup(tree1.unlock)
279
        tree2.lock_read()
280
        self.addCleanup(tree2.unlock)
2012.1.8 by Aaron Bentley
Merge from bzr.dev
281
        self.assertEqual([self.added(tree2, 'root-id'),
282
                          self.added(tree2, 'a-id'), 
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
283
                          self.added(tree2, 'b-id'), 
2012.1.8 by Aaron Bentley
Merge from bzr.dev
284
                          self.added(tree2, 'c-id'),
285
                          self.deleted(tree1, 'empty-root-id')],
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
286
                         list(tree2._iter_changes(tree1)))
2012.1.1 by Aaron Bentley
Implement change iterator
287
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
288
    def test_empty_to_abc_content_a_only(self):
289
        tree1 = self.make_branch_and_tree('1')
290
        tree2 = self.make_to_branch_and_tree('2')
291
        tree1 = self.get_tree_no_parents_no_content(tree1)
292
        tree2 = self.get_to_tree_no_parents_abc_content(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.
293
        tree1.lock_read()
294
        self.addCleanup(tree1.unlock)
295
        tree2.lock_read()
296
        self.addCleanup(tree2.unlock)
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
297
        self.assertEqual([self.added(tree2, 'a-id')],
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
298
                         list(tree2._iter_changes(tree1, 
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
299
                                                 specific_file_ids=['a-id'])))
300
        self.assertEqual([self.deleted(tree2, 'a-id')],
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
301
                         list(tree1._iter_changes(tree2, 
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
302
                                                 specific_file_ids=['a-id'])))
303
304
    def test_empty_to_abc_content_a_and_c_only(self):
305
        tree1 = self.make_branch_and_tree('1')
306
        tree2 = self.make_to_branch_and_tree('2')
307
        tree1 = self.get_tree_no_parents_no_content(tree1)
308
        tree2 = self.get_to_tree_no_parents_abc_content(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.
309
        tree1.lock_read()
310
        self.addCleanup(tree1.unlock)
311
        tree2.lock_read()
312
        self.addCleanup(tree2.unlock)
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
313
        self.assertEqual([self.added(tree2, 'a-id'),
314
                          self.added(tree2, 'c-id')],
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
315
                         list(tree2._iter_changes(tree1, 
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
316
                                                 specific_file_ids=['a-id', 
317
                                                                    'c-id'])))
318
        d = self.intertree_class(tree1, tree2).compare(
319
            specific_files=['a', 'b/c'])
320
2012.1.1 by Aaron Bentley
Implement change iterator
321
    def test_abc_content(self):
322
        tree1 = self.make_branch_and_tree('1')
323
        tree2 = self.make_to_branch_and_tree('2')
324
        tree1 = self.get_tree_no_parents_no_content(tree1)
325
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
326
        def deleted(file_id):
327
            entry = tree2.inventory[file_id]
328
            path = tree2.id2path(file_id)
329
            return (file_id, path, True, (True, False), 
330
                    (entry.parent_id, None),
331
                    (entry.name, None), (entry.kind, None), 
332
                    (entry.executable, None))
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
        self.addCleanup(tree1.unlock)
335
        tree2.lock_read()
336
        self.addCleanup(tree2.unlock)
2012.1.8 by Aaron Bentley
Merge from bzr.dev
337
        self.assertEqual([self.added(tree1, 'empty-root-id'), 
338
                          deleted('root-id'), deleted('a-id'), 
339
                          deleted('b-id'), deleted('c-id')],
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
340
                          list(tree1._iter_changes(tree2)))
2012.1.1 by Aaron Bentley
Implement change iterator
341
342
    def test_content_modification(self):
343
        tree1 = self.make_branch_and_tree('1')
344
        tree2 = self.make_to_branch_and_tree('2')
345
        tree1 = self.get_tree_no_parents_abc_content(tree1)
346
        tree2 = self.get_to_tree_no_parents_abc_content_2(tree2)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
347
        root_id = tree1.inventory.root.file_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.
348
        tree1.lock_read()
349
        self.addCleanup(tree1.unlock)
350
        tree2.lock_read()
351
        self.addCleanup(tree2.unlock)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
352
        self.assertEqual([('a-id', 'a', True, (True, True), 
353
                          (root_id, root_id), ('a', 'a'), 
354
                          ('file', 'file'), (False, False))], 
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
355
                         list(tree2._iter_changes(tree1)))
2012.1.1 by Aaron Bentley
Implement change iterator
356
357
    def test_meta_modification(self):
358
        tree1 = self.make_branch_and_tree('1')
359
        tree2 = self.make_to_branch_and_tree('2')
360
        tree1 = self.get_tree_no_parents_abc_content(tree1)
361
        tree2 = self.get_to_tree_no_parents_abc_content_3(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.
362
        tree1.lock_read()
363
        self.addCleanup(tree1.unlock)
364
        tree2.lock_read()
365
        self.addCleanup(tree2.unlock)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
366
        self.assertEqual([('c-id', 'b/c', False, (True, True), 
367
                          ('b-id', 'b-id'), ('c', 'c'), ('file', 'file'), 
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
368
                          (False, True))], list(tree2._iter_changes(tree1)))
2012.1.1 by Aaron Bentley
Implement change iterator
369
370
    def test_file_rename(self):
371
        tree1 = self.make_branch_and_tree('1')
372
        tree2 = self.make_to_branch_and_tree('2')
373
        tree1 = self.get_tree_no_parents_abc_content(tree1)
374
        tree2 = self.get_to_tree_no_parents_abc_content_4(tree2)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
375
        root_id = tree1.inventory.root.file_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.
376
        tree1.lock_read()
377
        self.addCleanup(tree1.unlock)
378
        tree2.lock_read()
379
        self.addCleanup(tree2.unlock)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
380
        self.assertEqual([('a-id', 'd', False, (True, True), 
381
                          (root_id, root_id), ('a', 'd'), ('file', 'file'),
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
382
                          (False, False))], list(tree2._iter_changes(tree1)))
2012.1.1 by Aaron Bentley
Implement change iterator
383
384
    def test_file_rename_and_modification(self):
385
        tree1 = self.make_branch_and_tree('1')
386
        tree2 = self.make_to_branch_and_tree('2')
387
        tree1 = self.get_tree_no_parents_abc_content(tree1)
388
        tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
389
        root_id = tree1.inventory.root.file_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.
390
        tree1.lock_read()
391
        self.addCleanup(tree1.unlock)
392
        tree2.lock_read()
393
        self.addCleanup(tree2.unlock)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
394
        self.assertEqual([('a-id', 'd', True, (True, True), 
395
                          (root_id, root_id), ('a', 'd'), ('file', 'file'),
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
396
                           (False, False))], list(tree2._iter_changes(tree1)))
2012.1.1 by Aaron Bentley
Implement change iterator
397
398
    def test_file_rename_and_meta_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)
402
        tree2 = self.get_to_tree_no_parents_abc_content_6(tree2)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
403
        root_id = tree1.inventory.root.file_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.
404
        tree1.lock_read()
405
        self.addCleanup(tree1.unlock)
406
        tree2.lock_read()
407
        self.addCleanup(tree2.unlock)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
408
        self.assertEqual([('c-id', 'e', False, (True, True), 
409
                          ('b-id', root_id), ('c', 'e'), ('file', 'file'), 
2012.1.10 by Aaron Bentley
Make iter_changes private, so it can be changed freely
410
                          (False, True))], list(tree2._iter_changes(tree1)))
2012.1.1 by Aaron Bentley
Implement change iterator
411
412
    def test_unchanged_with_renames_and_modifications(self):
413
        """want_unchanged should generate a list of unchanged entries."""
414
        tree1 = self.make_branch_and_tree('1')
415
        tree2 = self.make_to_branch_and_tree('2')
416
        tree1 = self.get_tree_no_parents_abc_content(tree1)
417
        tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
418
        root_id = tree1.inventory.root.file_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.
419
        tree1.lock_read()
420
        self.addCleanup(tree1.unlock)
421
        tree2.lock_read()
422
        self.addCleanup(tree2.unlock)
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
423
        def unchanged(file_id):
424
            entry = tree1.inventory[file_id]
425
            parent = entry.parent_id
426
            name = entry.name
427
            kind = entry.kind
428
            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.
429
            return (file_id, tree1.id2path(file_id), False, (True, True),
430
                   (parent, parent), (name, name), (kind, kind),
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
431
                   (executable, executable))
432
        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.
433
                          ('a-id', 'd', True, (True, True),
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
434
                          (root_id, root_id), ('a', 'd'), ('file', 'file'),
435
                          (False, False)), unchanged('c-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.
436
                         list(tree2._iter_changes(tree1,
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
437
                                                 include_unchanged=True)))