/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/workingtree_implementations/test_inv.py

Merge with serialize-transform

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
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 interface conformance of inventories of working trees."""
 
18
 
 
19
 
 
20
import os
 
21
import time
 
22
 
 
23
from bzrlib import (
 
24
    errors,
 
25
    inventory,
 
26
    )
 
27
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
28
 
 
29
 
 
30
class TestRevert(TestCaseWithWorkingTree):
 
31
 
 
32
    def test_dangling_id(self):
 
33
        wt = self.make_branch_and_tree('b1')
 
34
        wt.lock_tree_write()
 
35
        self.addCleanup(wt.unlock)
 
36
        self.assertEqual(len(wt.inventory), 1)
 
37
        open('b1/a', 'wb').write('a test\n')
 
38
        wt.add('a')
 
39
        self.assertEqual(len(wt.inventory), 2)
 
40
        wt.flush() # workaround revert doing wt._write_inventory for now.
 
41
        os.unlink('b1/a')
 
42
        wt.revert()
 
43
        self.assertEqual(len(wt.inventory), 1)
 
44
 
 
45
 
 
46
class TestApplyInventoryDelta(TestCaseWithWorkingTree):
 
47
 
 
48
    def test_add(self):
 
49
        wt = self.make_branch_and_tree('.')
 
50
        wt.lock_write()
 
51
        self.addCleanup(wt.unlock)
 
52
        root_id = wt.get_root_id()
 
53
        wt.apply_inventory_delta([(None, 'bar/foo', 'foo-id',
 
54
            inventory.InventoryFile('foo-id', 'foo', parent_id='bar-id')),
 
55
            (None, 'bar', 'bar-id', inventory.InventoryDirectory('bar-id',
 
56
            'bar', parent_id=root_id))])
 
57
        self.assertEqual('bar/foo', wt.inventory.id2path('foo-id'))
 
58
        self.assertEqual('bar', wt.inventory.id2path('bar-id'))
 
59
 
 
60
    def test_remove(self):
 
61
        wt = self.make_branch_and_tree('.')
 
62
        wt.lock_write()
 
63
        self.addCleanup(wt.unlock)
 
64
        self.build_tree(['foo/', 'foo/bar'])
 
65
        wt.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
 
66
        wt.apply_inventory_delta([('foo', None, 'foo-id', None),
 
67
                                  ('foo/bar', None, 'bar-id', None)])
 
68
        self.assertIs(None, wt.path2id('foo'))
 
69
 
 
70
    def test_rename_dir_with_children(self):
 
71
        wt = self.make_branch_and_tree('.')
 
72
        wt.lock_write()
 
73
        root_id = wt.get_root_id()
 
74
        self.addCleanup(wt.unlock)
 
75
        self.build_tree(['foo/', 'foo/bar'])
 
76
        wt.add(['foo', 'foo/bar'],
 
77
               ['foo-id', 'bar-id'])
 
78
        wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
 
79
            inventory.InventoryDirectory('foo-id', 'baz', root_id))])
 
80
        # foo/bar should have been followed the rename of its parent to baz/bar
 
81
        self.assertEqual('baz', wt.id2path('foo-id'))
 
82
        self.assertEqual('baz/bar', wt.id2path('bar-id'))
 
83
 
 
84
    def test_rename_dir_with_children_with_children(self):
 
85
        wt = self.make_branch_and_tree('.')
 
86
        wt.lock_write()
 
87
        root_id = wt.get_root_id()
 
88
        self.addCleanup(wt.unlock)
 
89
        self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz'])
 
90
        wt.add(['foo', 'foo/bar', 'foo/bar/baz'],
 
91
               ['foo-id', 'bar-id', 'baz-id'])
 
92
        wt.apply_inventory_delta([('foo', 'quux', 'foo-id',
 
93
            inventory.InventoryDirectory('foo-id', 'quux', root_id))])
 
94
        # foo/bar/baz should have been followed the rename of its parent's
 
95
        # parent to quux/bar/baz
 
96
        self.assertEqual('quux/bar/baz', wt.id2path('baz-id'))
 
97
 
 
98
    def test_rename_file(self):
 
99
        wt = self.make_branch_and_tree('.')
 
100
        wt.lock_write()
 
101
        self.addCleanup(wt.unlock)
 
102
        self.build_tree(['foo/', 'foo/bar', 'baz/'])
 
103
        wt.add(['foo', 'foo/bar', 'baz'],
 
104
               ['foo-id', 'bar-id', 'baz-id'])
 
105
        wt.apply_inventory_delta([('foo/bar', 'baz/bar', 'bar-id',
 
106
            inventory.InventoryFile('bar-id', 'bar', 'baz-id'))])
 
107
        self.assertEqual('baz/bar', wt.id2path('bar-id'))
 
108
 
 
109
    def test_rename_swap(self):
 
110
        """Test the swap-names edge case.
 
111
 
 
112
        foo and bar should swap names, but retain their children.  If this
 
113
        works, any simpler rename ought to work.
 
114
        """
 
115
        wt = self.make_branch_and_tree('.')
 
116
        wt.lock_write()
 
117
        root_id = wt.get_root_id()
 
118
        self.addCleanup(wt.unlock)
 
119
        self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux'])
 
120
        wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'],
 
121
               ['foo-id', 'bar-id', 'baz-id', 'qux-id'])
 
122
        wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
 
123
            inventory.InventoryDirectory('foo-id', 'baz', root_id)),
 
124
            ('baz', 'foo', 'baz-id',
 
125
            inventory.InventoryDirectory('baz-id', 'foo', root_id))])
 
126
        self.assertEqual('baz/bar', wt.id2path('bar-id'))
 
127
        self.assertEqual('foo/qux', wt.id2path('qux-id'))
 
128
 
 
129
    def test_child_rename_ordering(self):
 
130
        """Test the rename-parent, move child edge case.
 
131
 
 
132
        (A naive implementation may move the parent first, and then be
 
133
         unable to find the child.)
 
134
        """
 
135
        wt = self.make_branch_and_tree('.')
 
136
        root_id = wt.get_root_id()
 
137
        self.build_tree(['dir/', 'dir/child', 'other/'])
 
138
        wt.add(['dir', 'dir/child', 'other'],
 
139
               ['dir-id', 'child-id', 'other-id'])
 
140
        # this delta moves dir-id to dir2 and reparents 
 
141
        # child-id to a parent of other-id
 
142
        wt.apply_inventory_delta([('dir', 'dir2', 'dir-id',
 
143
            inventory.InventoryDirectory('dir-id', 'dir2', root_id)),
 
144
            ('dir/child', 'other/child', 'child-id',
 
145
             inventory.InventoryFile('child-id', 'child', 'other-id'))])
 
146
        self.assertEqual('dir2', wt.id2path('dir-id'))
 
147
        self.assertEqual('other/child', wt.id2path('child-id'))
 
148
 
 
149
    def test_replace_root(self):
 
150
        wt = self.make_branch_and_tree('.')
 
151
        wt.lock_write()
 
152
        self.addCleanup(wt.unlock)
 
153
 
 
154
        root_id = wt.get_root_id()
 
155
        wt.apply_inventory_delta([('', None, root_id, None),
 
156
            (None, '', 'root-id',
 
157
             inventory.InventoryDirectory('root-id', '', None))])