/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 breezy/tests/per_workingtree/test_add.py

  • Committer: Jelmer Vernooij
  • Date: 2018-03-24 10:24:48 UTC
  • mfrom: (6910 work)
  • mto: This revision was merged to the branch mainline in revision 6913.
  • Revision ID: jelmer@jelmer.uk-20180324102448-132p8l8t5ogdzhhu
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from breezy.bzr import (
24
24
    inventory,
25
25
    )
26
 
from breezy.tests.matchers import HasLayout
 
26
from breezy.tests.matchers import HasLayout, HasPathRelations
27
27
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
28
28
 
29
29
 
33
33
        """Check that the tree has the correct layout."""
34
34
        self.assertThat(tree, HasLayout(expected))
35
35
 
 
36
    def assertPathRelations(self, previous_tree, tree, relations):
 
37
        self.assertThat(tree, HasPathRelations(previous_tree, relations))
 
38
 
36
39
    def test_add_one(self):
37
40
        tree = self.make_branch_and_tree('.')
38
41
        self.build_tree(['one'])
39
42
        tree.add('one')
40
 
        root_id = tree.get_root_id()
41
43
 
42
 
        self.assertTreeLayout(
43
 
            [('', root_id), ('one', tree.path2id('one'))], tree)
 
44
        self.assertTreeLayout(['', 'one'], tree)
44
45
 
45
46
    def test_add_existing_id(self):
46
47
        """Adding an entry with a pre-existing id raises DuplicateFileId"""
51
52
        tree.add(['a'])
52
53
        self.assertRaises(errors.DuplicateFileId,
53
54
                          tree.add, ['b'], [tree.path2id('a')])
54
 
        root_id = tree.get_root_id()
55
55
        # And the entry should not have been added.
56
 
        self.assertTreeLayout([('', root_id), ('a', tree.path2id('a'))], tree)
 
56
        self.assertTreeLayout(['', 'a'], tree)
57
57
 
58
58
    def test_add_old_id(self):
59
59
        """We can add an old id, as long as it doesn't exist now."""
64
64
        tree.add(['a'])
65
65
        file_id = tree.path2id('a')
66
66
        tree.commit('first')
67
 
        root_id = tree.get_root_id()
68
67
        # And the entry should not have been added.
69
68
        tree.unversion(['a'])
70
69
        tree.add(['b'], [file_id])
71
 
        self.assertTreeLayout([('', root_id), ('b', file_id)], tree)
72
 
        self.assertTreeLayout([('', root_id), ('a', file_id)],
73
 
                              tree.basis_tree())
 
70
        self.assertPathRelations(
 
71
                tree.basis_tree(), tree,
 
72
                [('', ''), ('b', 'a')])
74
73
 
75
74
    def test_add_one_list(self):
76
75
        tree = self.make_branch_and_tree('.')
77
76
        self.build_tree(['one'])
78
77
        tree.add(['one'])
79
 
        root_id = tree.get_root_id()
80
78
 
81
 
        self.assertTreeLayout(
82
 
            [('', root_id), ('one', tree.path2id('one'))], tree)
 
79
        self.assertTreeLayout(['', 'one'], tree)
83
80
 
84
81
    def test_add_one_new_id(self):
85
82
        tree = self.make_branch_and_tree('.')
86
83
        self.build_tree(['one'])
87
84
        tree.add(['one'])
88
 
        root_id = tree.get_root_id()
89
 
        one_id = tree.path2id('one')
90
85
 
91
 
        self.assertTreeLayout([('', root_id), ('one', one_id)], tree)
 
86
        self.assertTreeLayout(['', 'one'], tree)
92
87
 
93
88
    def test_add_unicode(self):
94
89
        tree = self.make_branch_and_tree('.')
97
92
        except UnicodeError:
98
93
            raise tests.TestSkipped('Filesystem does not support filename.')
99
94
        tree.add([u'f\xf6'])
100
 
        root_id = tree.get_root_id()
101
 
        foo_id = tree.path2id(u'f\xf6')
102
95
 
103
 
        self.assertTreeLayout([('', root_id), (u'f\xf6', foo_id)], tree)
 
96
        self.assertTreeLayout(['', u'f\xf6'], tree)
104
97
 
105
98
    def test_add_subdir_with_ids(self):
106
99
        tree = self.make_branch_and_tree('.')
122
115
        tree.add(['dir'])
123
116
        tree.add(['dir/subdir'])
124
117
        tree.add(['dir/subdir/foo'])
125
 
        root_id = tree.get_root_id()
126
118
 
127
 
        self.assertTreeLayout([
128
 
            ('', root_id),
129
 
            ('dir/', tree.path2id('dir')),
130
 
            ('dir/subdir/', tree.path2id('dir/subdir')),
131
 
            ('dir/subdir/foo', tree.path2id('dir/subdir/foo'))],
132
 
            tree)
 
119
        self.assertTreeLayout(
 
120
            ['', 'dir/', 'dir/subdir/', 'dir/subdir/foo'], tree)
133
121
 
134
122
    def test_add_multiple(self):
135
123
        tree = self.make_branch_and_tree('.')
136
124
        self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
137
125
        tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'])
138
 
        root_id = tree.get_root_id()
139
126
 
140
 
        self.assertTreeLayout([
141
 
            (p, tree.path2id(p))
142
 
            for p in ['', 'a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo']],
 
127
        self.assertTreeLayout(
 
128
            ['', 'a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'],
143
129
            tree)
144
130
 
145
131
    def test_add_multiple_with_file_ids(self):
149
135
        self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
150
136
        tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'],
151
137
                 ['a-id', 'b-id', 'dir-id', 'subdir-id', 'foo-id'])
152
 
        root_id = tree.get_root_id()
153
138
 
154
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
139
        self.assertTreeLayout([('', tree.get_root_id()), ('a', 'a-id'), ('b', 'b-id'),
155
140
                               ('dir/', 'dir-id'), ('dir/subdir/', 'subdir-id'),
156
141
                               ('dir/subdir/foo', 'foo-id')], tree)
157
142
 
161
146
            raise tests.TestNotApplicable(
162
147
                'format does not support versioned directories')
163
148
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
164
 
        root_id = tree.get_root_id()
165
149
 
166
150
        self.assertRaises(errors.NotVersionedError,
167
151
                          tree.add, ['dir/subdir'])
168
 
        self.assertTreeLayout([('', root_id)], tree)
 
152
        self.assertTreeLayout([''], tree)
169
153
 
170
154
    def test_add_after_remove(self):
171
155
        tree = self.make_branch_and_tree('.')
173
157
            raise tests.TestNotApplicable(
174
158
                'format does not support versioned directories')
175
159
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
176
 
        root_id = tree.get_root_id()
177
160
        tree.add(['dir'])
178
161
        tree.commit('dir')
179
162
        tree.unversion(['dir'])