~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_add.py

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for interface conformance of 'WorkingTree.add'"""
18
18
 
19
 
import os
20
 
 
21
19
from bzrlib import (
22
20
    errors,
23
21
    inventory,
24
 
    osutils,
25
22
    tests,
26
23
    )
 
24
from bzrlib.tests.matchers import HasLayout
27
25
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
28
26
 
29
27
 
30
28
class TestAdd(TestCaseWithWorkingTree):
31
29
 
32
 
    def get_tree_layout(self, tree):
33
 
        """Get the (path, file_id) pairs for the current tree."""
34
 
        tree.lock_read()
35
 
        try:
36
 
            return [(path, ie.file_id) for path, ie
37
 
                    in tree.iter_entries_by_dir()]
38
 
        finally:
39
 
            tree.unlock()
40
 
 
41
30
    def assertTreeLayout(self, expected, tree):
42
31
        """Check that the tree has the correct layout."""
43
 
        actual = self.get_tree_layout(tree)
44
 
        self.assertEqual(expected, actual)
 
32
        self.assertThat(tree, HasLayout(expected))
45
33
 
46
34
    def test_add_one(self):
47
35
        tree = self.make_branch_and_tree('.')
113
101
        tree.add(['dir/subdir/foo'], ['foo-id'])
114
102
        root_id = tree.get_root_id()
115
103
 
116
 
        self.assertTreeLayout([('', root_id), ('dir', 'dir-id'),
117
 
                               ('dir/subdir', 'subdir-id'),
 
104
        self.assertTreeLayout([('', root_id), ('dir/', 'dir-id'),
 
105
                               ('dir/subdir/', 'subdir-id'),
118
106
                               ('dir/subdir/foo', 'foo-id')], tree)
119
107
 
120
108
    def test_add_multiple(self):
125
113
        root_id = tree.get_root_id()
126
114
 
127
115
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
128
 
                               ('dir', 'dir-id'), ('dir/subdir', 'subdir-id'),
 
116
                               ('dir/', 'dir-id'), ('dir/subdir/', 'subdir-id'),
129
117
                               ('dir/subdir/foo', 'foo-id')], tree)
130
118
 
131
119
    def test_add_invalid(self):
153
141
        tree = self.make_branch_and_tree('.')
154
142
        tree.lock_write()
155
143
        tree.add('')
156
 
        self.assertEqual([tree.path2id('')], list(tree))
 
144
        self.assertEqual([tree.path2id('')], list(tree.all_file_ids()))
157
145
        # the root should have been changed to be a new unique root.
158
146
        self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
159
147
        tree.unlock()