~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_inv.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for interface conformance of inventories of working trees."""
18
18
 
19
19
 
20
20
import os
 
21
import time
21
22
 
22
 
from bzrlib import inventory, tests
23
 
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
 
23
from bzrlib import (
 
24
    errors,
 
25
    inventory,
 
26
    )
 
27
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
24
28
 
25
29
 
26
30
class TestRevert(TestCaseWithWorkingTree):
29
33
        wt = self.make_branch_and_tree('b1')
30
34
        wt.lock_tree_write()
31
35
        self.addCleanup(wt.unlock)
32
 
        self.assertEqual(len(wt.all_file_ids()), 1)
33
 
        with open('b1/a', 'wb') as f: f.write('a test\n')
 
36
        self.assertEqual(len(wt.inventory), 1)
 
37
        open('b1/a', 'wb').write('a test\n')
34
38
        wt.add('a')
35
 
        self.assertEqual(len(wt.all_file_ids()), 2)
 
39
        self.assertEqual(len(wt.inventory), 2)
36
40
        wt.flush() # workaround revert doing wt._write_inventory for now.
37
41
        os.unlink('b1/a')
38
42
        wt.revert()
39
 
        self.assertEqual(len(wt.all_file_ids()), 1)
 
43
        self.assertEqual(len(wt.inventory), 1)
40
44
 
41
45
 
42
46
class TestApplyInventoryDelta(TestCaseWithWorkingTree):
43
47
 
44
 
    def setUp(self):
45
 
        super(TestApplyInventoryDelta, self).setUp()
46
 
        if not self.bzrdir_format.repository_format.supports_full_versioned_files:
47
 
            raise tests.TestNotApplicable(
48
 
                "format does not support inventory deltas")
49
 
 
50
48
    def test_add(self):
51
49
        wt = self.make_branch_and_tree('.')
52
50
        wt.lock_write()
56
54
            inventory.InventoryFile('foo-id', 'foo', parent_id='bar-id')),
57
55
            (None, 'bar', 'bar-id', inventory.InventoryDirectory('bar-id',
58
56
            'bar', parent_id=root_id))])
59
 
        self.assertEqual('bar/foo', wt.id2path('foo-id'))
60
 
        self.assertEqual('bar', wt.id2path('bar-id'))
 
57
        self.assertEqual('bar/foo', wt.inventory.id2path('foo-id'))
 
58
        self.assertEqual('bar', wt.inventory.id2path('bar-id'))
61
59
 
62
60
    def test_remove(self):
63
61
        wt = self.make_branch_and_tree('.')
139
137
        self.build_tree(['dir/', 'dir/child', 'other/'])
140
138
        wt.add(['dir', 'dir/child', 'other'],
141
139
               ['dir-id', 'child-id', 'other-id'])
142
 
        # this delta moves dir-id to dir2 and reparents
 
140
        # this delta moves dir-id to dir2 and reparents 
143
141
        # child-id to a parent of other-id
144
142
        wt.apply_inventory_delta([('dir', 'dir2', 'dir-id',
145
143
            inventory.InventoryDirectory('dir-id', 'dir2', root_id)),
157
155
        wt.apply_inventory_delta([('', None, root_id, None),
158
156
            (None, '', 'root-id',
159
157
             inventory.InventoryDirectory('root-id', '', None))])
160
 
 
161
 
 
162
 
class TestTreeReference(TestCaseWithWorkingTree):
163
 
 
164
 
    def test_tree_reference_matches_inv(self):
165
 
        base = self.make_branch_and_tree('base')
166
 
        if base.branch.repository._format.supports_full_versioned_files:
167
 
            raise tests.TestNotApplicable(
168
 
                "format does not support inventory deltas")
169
 
        if not base.supports_tree_reference():
170
 
            raise tests.TestNotApplicable("wt doesn't support nested trees")
171
 
        # We add it as a directory, but it becomes a tree-reference
172
 
        base.add(['subdir'], ['subdir-id'], ['directory'])
173
 
        subdir = self.make_branch_and_tree('base/subdir')
174
 
        self.addCleanup(base.lock_read().unlock)
175
 
        # Note: we aren't strict about ie.kind being 'directory' here, what we
176
 
        # are strict about is that wt.inventory should match
177
 
        # wt.current_dirstate()'s idea about what files are where.
178
 
        ie = base.inventory['subdir-id']
179
 
        self.assertEqual('directory', ie.kind)
180
 
        path, ie = base.iter_entries_by_dir(['subdir-id']).next()
181
 
        self.assertEqual('subdir', path)
182
 
        self.assertEqual('tree-reference', ie.kind)