/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/intertree_implementations/test_compare.py

[merge] bzr.dev 2255, resolve conflicts, update copyrights

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Tests for the InterTree.compare() function."""
18
18
 
 
19
import os
 
20
 
19
21
from bzrlib import errors
20
22
from bzrlib.tests.intertree_implementations import TestCaseWithTwoTrees
21
23
 
49
51
        self.assertEqual([], d.renamed)
50
52
        self.assertEqual([], d.unchanged)
51
53
 
 
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
 
52
70
    def test_abc_content_to_empty(self):
53
71
        tree1 = self.make_branch_and_tree('1')
54
72
        tree2 = self.make_to_branch_and_tree('2')
220
238
            self.intertree_class(tree1, tree2).compare,
221
239
            specific_files=['d'],
222
240
            require_versioned=True)
 
241
 
 
242
 
 
243
class TestIterChanges(TestCaseWithTwoTrees):
 
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)
 
251
        self.assertEqual([], list(tree2._iter_changes(tree1)))
 
252
 
 
253
    def added(self, tree, file_id):
 
254
        entry = tree.inventory[file_id]
 
255
        path = tree.id2path(file_id)
 
256
        return (file_id, path, True, (False, True), (None, entry.parent_id),
 
257
                (None, entry.name), (None, entry.kind), 
 
258
                (None, entry.executable))
 
259
 
 
260
    def deleted(self, tree, file_id):
 
261
        entry = tree.inventory[file_id]
 
262
        path = tree.id2path(file_id)
 
263
        return (file_id, path, True, (True, False), (entry.parent_id, None),
 
264
                (entry.name, None), (entry.kind, None), 
 
265
                (entry.executable, None))
 
266
 
 
267
    def test_empty_to_abc_content(self):
 
268
        tree1 = self.make_branch_and_tree('1')
 
269
        tree2 = self.make_to_branch_and_tree('2')
 
270
        tree1 = self.get_tree_no_parents_no_content(tree1)
 
271
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
 
272
            
 
273
        self.assertEqual([self.added(tree2, 'root-id'),
 
274
                          self.added(tree2, 'a-id'), 
 
275
                          self.added(tree2, 'b-id'), 
 
276
                          self.added(tree2, 'c-id'),
 
277
                          self.deleted(tree1, 'empty-root-id')],
 
278
                         list(tree2._iter_changes(tree1)))
 
279
 
 
280
    def test_empty_to_abc_content_a_only(self):
 
281
        tree1 = self.make_branch_and_tree('1')
 
282
        tree2 = self.make_to_branch_and_tree('2')
 
283
        tree1 = self.get_tree_no_parents_no_content(tree1)
 
284
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
 
285
        self.assertEqual([self.added(tree2, 'a-id')],
 
286
                         list(tree2._iter_changes(tree1, 
 
287
                                                 specific_file_ids=['a-id'])))
 
288
        self.assertEqual([self.deleted(tree2, 'a-id')],
 
289
                         list(tree1._iter_changes(tree2, 
 
290
                                                 specific_file_ids=['a-id'])))
 
291
 
 
292
    def test_empty_to_abc_content_a_and_c_only(self):
 
293
        tree1 = self.make_branch_and_tree('1')
 
294
        tree2 = self.make_to_branch_and_tree('2')
 
295
        tree1 = self.get_tree_no_parents_no_content(tree1)
 
296
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
 
297
        self.assertEqual([self.added(tree2, 'a-id'),
 
298
                          self.added(tree2, 'c-id')],
 
299
                         list(tree2._iter_changes(tree1, 
 
300
                                                 specific_file_ids=['a-id', 
 
301
                                                                    'c-id'])))
 
302
        d = self.intertree_class(tree1, tree2).compare(
 
303
            specific_files=['a', 'b/c'])
 
304
 
 
305
    def test_abc_content(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)
 
309
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
 
310
        def deleted(file_id):
 
311
            entry = tree2.inventory[file_id]
 
312
            path = tree2.id2path(file_id)
 
313
            return (file_id, path, True, (True, False), 
 
314
                    (entry.parent_id, None),
 
315
                    (entry.name, None), (entry.kind, None), 
 
316
                    (entry.executable, None))
 
317
        self.assertEqual([self.added(tree1, 'empty-root-id'), 
 
318
                          deleted('root-id'), deleted('a-id'), 
 
319
                          deleted('b-id'), deleted('c-id')],
 
320
                          list(tree1._iter_changes(tree2)))
 
321
 
 
322
    def test_content_modification(self):
 
323
        tree1 = self.make_branch_and_tree('1')
 
324
        tree2 = self.make_to_branch_and_tree('2')
 
325
        tree1 = self.get_tree_no_parents_abc_content(tree1)
 
326
        tree2 = self.get_to_tree_no_parents_abc_content_2(tree2)
 
327
        root_id = tree1.inventory.root.file_id
 
328
        self.assertEqual([('a-id', 'a', True, (True, True), 
 
329
                          (root_id, root_id), ('a', 'a'), 
 
330
                          ('file', 'file'), (False, False))], 
 
331
                         list(tree2._iter_changes(tree1)))
 
332
 
 
333
    def test_meta_modification(self):
 
334
        tree1 = self.make_branch_and_tree('1')
 
335
        tree2 = self.make_to_branch_and_tree('2')
 
336
        tree1 = self.get_tree_no_parents_abc_content(tree1)
 
337
        tree2 = self.get_to_tree_no_parents_abc_content_3(tree2)
 
338
        self.assertEqual([('c-id', 'b/c', False, (True, True), 
 
339
                          ('b-id', 'b-id'), ('c', 'c'), ('file', 'file'), 
 
340
                          (False, True))], list(tree2._iter_changes(tree1)))
 
341
 
 
342
    def test_file_rename(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_4(tree2)
 
347
        root_id = tree1.inventory.root.file_id
 
348
        self.assertEqual([('a-id', 'd', False, (True, True), 
 
349
                          (root_id, root_id), ('a', 'd'), ('file', 'file'),
 
350
                          (False, False))], list(tree2._iter_changes(tree1)))
 
351
 
 
352
    def test_file_rename_and_modification(self):
 
353
        tree1 = self.make_branch_and_tree('1')
 
354
        tree2 = self.make_to_branch_and_tree('2')
 
355
        tree1 = self.get_tree_no_parents_abc_content(tree1)
 
356
        tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
 
357
        root_id = tree1.inventory.root.file_id
 
358
        self.assertEqual([('a-id', 'd', True, (True, True), 
 
359
                          (root_id, root_id), ('a', 'd'), ('file', 'file'),
 
360
                           (False, False))], list(tree2._iter_changes(tree1)))
 
361
 
 
362
    def test_file_rename_and_meta_modification(self):
 
363
        tree1 = self.make_branch_and_tree('1')
 
364
        tree2 = self.make_to_branch_and_tree('2')
 
365
        tree1 = self.get_tree_no_parents_abc_content(tree1)
 
366
        tree2 = self.get_to_tree_no_parents_abc_content_6(tree2)
 
367
        root_id = tree1.inventory.root.file_id
 
368
        self.assertEqual([('c-id', 'e', False, (True, True), 
 
369
                          ('b-id', root_id), ('c', 'e'), ('file', 'file'), 
 
370
                          (False, True))], list(tree2._iter_changes(tree1)))
 
371
 
 
372
    def test_unchanged_with_renames_and_modifications(self):
 
373
        """want_unchanged should generate a list of unchanged entries."""
 
374
        tree1 = self.make_branch_and_tree('1')
 
375
        tree2 = self.make_to_branch_and_tree('2')
 
376
        tree1 = self.get_tree_no_parents_abc_content(tree1)
 
377
        tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
 
378
        root_id = tree1.inventory.root.file_id
 
379
        def unchanged(file_id):
 
380
            entry = tree1.inventory[file_id]
 
381
            parent = entry.parent_id
 
382
            name = entry.name
 
383
            kind = entry.kind
 
384
            executable = entry.executable
 
385
            return (file_id, tree1.id2path(file_id), False, (True, True), 
 
386
                   (parent, parent), (name, name), (kind, kind), 
 
387
                   (executable, executable))
 
388
        self.assertEqual([unchanged(root_id), unchanged('b-id'),
 
389
                          ('a-id', 'd', True, (True, True), 
 
390
                          (root_id, root_id), ('a', 'd'), ('file', 'file'),
 
391
                          (False, False)), unchanged('c-id')],
 
392
                         list(tree2._iter_changes(tree1, 
 
393
                                                 include_unchanged=True)))