~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

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
 
19
21
from bzrlib import (
20
22
    errors,
21
23
    inventory,
 
24
    osutils,
22
25
    tests,
23
26
    )
24
 
from bzrlib.tests.matchers import HasLayout
25
27
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
26
28
 
27
29
 
28
30
class TestAdd(TestCaseWithWorkingTree):
29
31
 
 
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
 
30
41
    def assertTreeLayout(self, expected, tree):
31
42
        """Check that the tree has the correct layout."""
32
 
        self.assertThat(tree, HasLayout(expected))
 
43
        actual = self.get_tree_layout(tree)
 
44
        self.assertEqual(expected, actual)
33
45
 
34
46
    def test_add_one(self):
35
47
        tree = self.make_branch_and_tree('.')
101
113
        tree.add(['dir/subdir/foo'], ['foo-id'])
102
114
        root_id = tree.get_root_id()
103
115
 
104
 
        self.assertTreeLayout([('', root_id), ('dir/', 'dir-id'),
105
 
                               ('dir/subdir/', 'subdir-id'),
 
116
        self.assertTreeLayout([('', root_id), ('dir', 'dir-id'),
 
117
                               ('dir/subdir', 'subdir-id'),
106
118
                               ('dir/subdir/foo', 'foo-id')], tree)
107
119
 
108
120
    def test_add_multiple(self):
113
125
        root_id = tree.get_root_id()
114
126
 
115
127
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
116
 
                               ('dir/', 'dir-id'), ('dir/subdir/', 'subdir-id'),
 
128
                               ('dir', 'dir-id'), ('dir/subdir', 'subdir-id'),
117
129
                               ('dir/subdir/foo', 'foo-id')], tree)
118
130
 
119
131
    def test_add_invalid(self):
141
153
        tree = self.make_branch_and_tree('.')
142
154
        tree.lock_write()
143
155
        tree.add('')
144
 
        self.assertEqual([tree.path2id('')], list(tree.all_file_ids()))
 
156
        self.assertEqual([tree.path2id('')], list(tree))
145
157
        # the root should have been changed to be a new unique root.
146
158
        self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
147
159
        tree.unlock()