~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2006-09-19 16:17:31 UTC
  • mto: This revision was merged to the branch mainline in revision 2162.
  • Revision ID: abentley@panoramicfeedback.com-20060919161731-4a099268251f858c
Implement specific file id and dangling id handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
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')
232
250
        tree2 = self.get_to_tree_no_parents_no_content(tree2)
233
251
        self.assertEqual([], list(tree2.iter_changes(tree1)))
234
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
 
235
267
    def test_empty_to_abc_content(self):
236
268
        tree1 = self.make_branch_and_tree('1')
237
269
        tree2 = self.make_to_branch_and_tree('2')
238
270
        tree1 = self.get_tree_no_parents_no_content(tree1)
239
271
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
240
 
        def added(file_id):
241
 
            entry = tree2.inventory[file_id]
242
 
            path = tree2.id2path(file_id)
243
 
            return (file_id, path, True, (False, True), (None, entry.parent_id),
244
 
                    (None, entry.name), (None, entry.kind), 
245
 
                    (None, entry.executable))
246
272
            
247
 
        self.assertEqual([added('a-id'), added('b-id'), added('c-id')],
 
273
        self.assertEqual([self.added(tree2, 'a-id'), 
 
274
                          self.added(tree2, 'b-id'), 
 
275
                          self.added(tree2, 'c-id')],
248
276
                         list(tree2.iter_changes(tree1)))
249
277
 
 
278
    def test_empty_to_abc_content_a_only(self):
 
279
        tree1 = self.make_branch_and_tree('1')
 
280
        tree2 = self.make_to_branch_and_tree('2')
 
281
        tree1 = self.get_tree_no_parents_no_content(tree1)
 
282
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
 
283
        self.assertEqual([self.added(tree2, 'a-id')],
 
284
                         list(tree2.iter_changes(tree1, 
 
285
                                                 specific_file_ids=['a-id'])))
 
286
        self.assertEqual([self.deleted(tree2, 'a-id')],
 
287
                         list(tree1.iter_changes(tree2, 
 
288
                                                 specific_file_ids=['a-id'])))
 
289
 
 
290
    def test_empty_to_abc_content_a_and_c_only(self):
 
291
        tree1 = self.make_branch_and_tree('1')
 
292
        tree2 = self.make_to_branch_and_tree('2')
 
293
        tree1 = self.get_tree_no_parents_no_content(tree1)
 
294
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
 
295
        self.assertEqual([self.added(tree2, 'a-id'),
 
296
                          self.added(tree2, 'c-id')],
 
297
                         list(tree2.iter_changes(tree1, 
 
298
                                                 specific_file_ids=['a-id', 
 
299
                                                                    'c-id'])))
 
300
        d = self.intertree_class(tree1, tree2).compare(
 
301
            specific_files=['a', 'b/c'])
 
302
 
250
303
    def test_abc_content(self):
251
304
        tree1 = self.make_branch_and_tree('1')
252
305
        tree2 = self.make_to_branch_and_tree('2')