bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
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
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
16 |
|
17 |
"""Tests for interface conformance of 'WorkingTree.add'"""
|
|
18 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
19 |
from breezy import ( |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
20 |
errors, |
|
6670.4.3
by Jelmer Vernooij
Fix more imports. |
21 |
tests, |
22 |
)
|
|
23 |
from breezy.bzr import ( |
|
|
2255.7.74
by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4. |
24 |
inventory, |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
25 |
)
|
|
6883.5.9
by Jelmer Vernooij
Fix tests. |
26 |
from breezy.tests.matchers import HasLayout, HasPathRelations |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
27 |
from breezy.tests.per_workingtree import TestCaseWithWorkingTree |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
28 |
|
29 |
||
30 |
class TestAdd(TestCaseWithWorkingTree): |
|
31 |
||
32 |
def assertTreeLayout(self, expected, tree): |
|
33 |
"""Check that the tree has the correct layout.""" |
|
|
6072.2.2
by Jelmer Vernooij
Use HasLayout matcher. |
34 |
self.assertThat(tree, HasLayout(expected)) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
35 |
|
|
6883.5.8
by Jelmer Vernooij
Avoid using file ids. |
36 |
def assertPathRelations(self, previous_tree, tree, relations): |
37 |
self.assertThat(tree, HasPathRelations(previous_tree, relations)) |
|
38 |
||
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
39 |
def test_add_one(self): |
40 |
tree = self.make_branch_and_tree('.') |
|
41 |
self.build_tree(['one']) |
|
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
42 |
tree.add('one') |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
43 |
|
|
6883.5.8
by Jelmer Vernooij
Avoid using file ids. |
44 |
self.assertTreeLayout(['', 'one'], tree) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
45 |
|
|
2255.7.16
by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId. |
46 |
def test_add_existing_id(self): |
47 |
"""Adding an entry with a pre-existing id raises DuplicateFileId""" |
|
48 |
tree = self.make_branch_and_tree('.') |
|
|
6793.5.1
by Jelmer Vernooij
Hardcode fileids in fewer places. |
49 |
if not tree.supports_setting_file_ids(): |
|
6819.1.3
by Jelmer Vernooij
Use self.skipTest. |
50 |
self.skipTest("tree does not support setting file ids") |
|
2255.7.16
by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId. |
51 |
self.build_tree(['a', 'b']) |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
52 |
tree.add(['a']) |
|
7490.69.2
by Jelmer Vernooij
Move DuplicateFileId. |
53 |
self.assertRaises( |
54 |
inventory.DuplicateFileId, tree.add, ['b'], [tree.path2id('a')]) |
|
|
2255.7.16
by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId. |
55 |
# And the entry should not have been added.
|
|
6883.5.9
by Jelmer Vernooij
Fix tests. |
56 |
self.assertTreeLayout(['', 'a'], tree) |
|
2255.7.16
by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId. |
57 |
|
|
2255.7.17
by John Arbash Meinel
Add another test that makes sure we can add as long as the file_id isn't current. |
58 |
def test_add_old_id(self): |
59 |
"""We can add an old id, as long as it doesn't exist now.""" |
|
60 |
tree = self.make_branch_and_tree('.') |
|
|
6829.2.1
by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places. |
61 |
if not tree.supports_setting_file_ids(): |
62 |
self.skipTest("tree does not support setting file ids") |
|
|
2255.7.17
by John Arbash Meinel
Add another test that makes sure we can add as long as the file_id isn't current. |
63 |
self.build_tree(['a', 'b']) |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
64 |
tree.add(['a']) |
65 |
file_id = tree.path2id('a') |
|
|
6747.3.1
by Jelmer Vernooij
Avoid more uses of revision_id. |
66 |
tree.commit('first') |
|
2255.7.17
by John Arbash Meinel
Add another test that makes sure we can add as long as the file_id isn't current. |
67 |
# And the entry should not have been added.
|
|
6809.4.25
by Jelmer Vernooij
Add paths argument to .unversion. |
68 |
tree.unversion(['a']) |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
69 |
tree.add(['b'], [file_id]) |
|
6883.5.8
by Jelmer Vernooij
Avoid using file ids. |
70 |
self.assertPathRelations( |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
71 |
tree.basis_tree(), tree, |
72 |
[('', ''), ('b', 'a')]) |
|
|
2255.7.17
by John Arbash Meinel
Add another test that makes sure we can add as long as the file_id isn't current. |
73 |
|
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
74 |
def test_add_one_list(self): |
75 |
tree = self.make_branch_and_tree('.') |
|
76 |
self.build_tree(['one']) |
|
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
77 |
tree.add(['one']) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
78 |
|
|
6883.5.8
by Jelmer Vernooij
Avoid using file ids. |
79 |
self.assertTreeLayout(['', 'one'], tree) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
80 |
|
81 |
def test_add_one_new_id(self): |
|
82 |
tree = self.make_branch_and_tree('.') |
|
83 |
self.build_tree(['one']) |
|
84 |
tree.add(['one']) |
|
85 |
||
|
6883.5.8
by Jelmer Vernooij
Avoid using file ids. |
86 |
self.assertTreeLayout(['', 'one'], tree) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
87 |
|
88 |
def test_add_unicode(self): |
|
89 |
tree = self.make_branch_and_tree('.') |
|
90 |
try: |
|
91 |
self.build_tree([u'f\xf6']) |
|
92 |
except UnicodeError: |
|
93 |
raise tests.TestSkipped('Filesystem does not support filename.') |
|
94 |
tree.add([u'f\xf6']) |
|
95 |
||
|
6883.5.8
by Jelmer Vernooij
Avoid using file ids. |
96 |
self.assertTreeLayout(['', u'f\xf6'], tree) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
97 |
|
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
98 |
def test_add_subdir_with_ids(self): |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
99 |
tree = self.make_branch_and_tree('.') |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
100 |
if not tree.supports_setting_file_ids(): |
|
6819.1.3
by Jelmer Vernooij
Use self.skipTest. |
101 |
self.skipTest("tree does not support setting file ids") |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
102 |
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo']) |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
103 |
tree.add(['dir'], [b'dir-id']) |
104 |
tree.add(['dir/subdir'], [b'subdir-id']) |
|
105 |
tree.add(['dir/subdir/foo'], [b'foo-id']) |
|
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
106 |
root_id = tree.path2id('') |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
107 |
|
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
108 |
self.assertTreeLayout([('', root_id), ('dir/', b'dir-id'), |
109 |
('dir/subdir/', b'subdir-id'), |
|
110 |
('dir/subdir/foo', b'foo-id')], tree) |
|
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
111 |
|
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
112 |
def test_add_subdir(self): |
113 |
tree = self.make_branch_and_tree('.') |
|
114 |
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo']) |
|
115 |
tree.add(['dir']) |
|
116 |
tree.add(['dir/subdir']) |
|
117 |
tree.add(['dir/subdir/foo']) |
|
118 |
||
|
6883.5.8
by Jelmer Vernooij
Avoid using file ids. |
119 |
self.assertTreeLayout( |
120 |
['', 'dir/', 'dir/subdir/', 'dir/subdir/foo'], tree) |
|
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
121 |
|
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
122 |
def test_add_multiple(self): |
123 |
tree = self.make_branch_and_tree('.') |
|
124 |
self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo']) |
|
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
125 |
tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo']) |
126 |
||
|
6883.5.9
by Jelmer Vernooij
Fix tests. |
127 |
self.assertTreeLayout( |
|
6883.5.8
by Jelmer Vernooij
Avoid using file ids. |
128 |
['', 'a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'], |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
129 |
tree) |
130 |
||
131 |
def test_add_multiple_with_file_ids(self): |
|
132 |
tree = self.make_branch_and_tree('.') |
|
133 |
if not tree.supports_setting_file_ids(): |
|
|
6819.1.3
by Jelmer Vernooij
Use self.skipTest. |
134 |
self.skipTest("tree does not support setting file ids") |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
135 |
self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo']) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
136 |
tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'], |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
137 |
[b'a-id', b'b-id', b'dir-id', b'subdir-id', b'foo-id']) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
138 |
|
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
139 |
self.assertTreeLayout([('', tree.path2id('')), ('a', b'a-id'), ('b', b'b-id'), |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
140 |
('dir/', b'dir-id'), ('dir/subdir/', b'subdir-id'), |
141 |
('dir/subdir/foo', b'foo-id')], tree) |
|
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
142 |
|
143 |
def test_add_invalid(self): |
|
144 |
tree = self.make_branch_and_tree('.') |
|
|
6861.1.1
by Jelmer Vernooij
More foreign branch test fixes. |
145 |
if not tree._format.supports_versioned_directories: |
146 |
raise tests.TestNotApplicable( |
|
147 |
'format does not support versioned directories') |
|
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
148 |
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo']) |
149 |
||
150 |
self.assertRaises(errors.NotVersionedError, |
|
151 |
tree.add, ['dir/subdir']) |
|
|
6883.5.8
by Jelmer Vernooij
Avoid using file ids. |
152 |
self.assertTreeLayout([''], tree) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
153 |
|
154 |
def test_add_after_remove(self): |
|
155 |
tree = self.make_branch_and_tree('.') |
|
|
6861.1.1
by Jelmer Vernooij
More foreign branch test fixes. |
156 |
if not tree._format.supports_versioned_directories: |
157 |
raise tests.TestNotApplicable( |
|
158 |
'format does not support versioned directories') |
|
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
159 |
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo']) |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
160 |
tree.add(['dir']) |
|
6747.3.1
by Jelmer Vernooij
Avoid more uses of revision_id. |
161 |
tree.commit('dir') |
|
6809.4.25
by Jelmer Vernooij
Add paths argument to .unversion. |
162 |
tree.unversion(['dir']) |
|
2255.7.10
by John Arbash Meinel
Handle the case when we are adding a file to an empty directory. |
163 |
self.assertRaises(errors.NotVersionedError, |
|
6861.1.1
by Jelmer Vernooij
More foreign branch test fixes. |
164 |
tree.add, ['dir/subdir/foo']) |
|
2255.7.74
by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4. |
165 |
|
166 |
def test_add_root(self): |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
167 |
# adding the root should be a no-op, or at least not
|
|
2255.7.74
by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4. |
168 |
# do anything whacky.
|
169 |
tree = self.make_branch_and_tree('.') |
|
|
6861.1.1
by Jelmer Vernooij
More foreign branch test fixes. |
170 |
with tree.lock_write(): |
171 |
tree.add('') |
|
172 |
self.assertEqual([''], list(tree.all_versioned_paths())) |
|
173 |
# the root should have been changed to be a new unique root.
|
|
174 |
if tree._format.supports_setting_file_ids: |
|
175 |
self.assertNotEqual(inventory.ROOT_ID, tree.path2id('')) |
|
|
2323.4.1
by Robert Collins
dirstate correctness: allow adding paths present in the basis. |
176 |
|
177 |
def test_add_previously_added(self): |
|
178 |
# adding a path that was previously added should work
|
|
179 |
tree = self.make_branch_and_tree('.') |
|
180 |
self.build_tree(['foo']) |
|
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
181 |
tree.add(['foo']) |
|
6809.4.25
by Jelmer Vernooij
Add paths argument to .unversion. |
182 |
tree.unversion(['foo']) |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
183 |
tree.add(['foo']) |
184 |
self.assertTrue(tree.has_filename('foo')) |
|
185 |
||
186 |
def test_add_previously_added_with_file_id(self): |
|
187 |
# adding a path that was previously added should work
|
|
188 |
tree = self.make_branch_and_tree('.') |
|
189 |
if not tree.supports_setting_file_ids(): |
|
|
6819.1.3
by Jelmer Vernooij
Use self.skipTest. |
190 |
self.skipTest("tree does not support setting file ids") |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
191 |
self.build_tree(['foo']) |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
192 |
tree.add(['foo'], [b'foo-id']) |
|
6809.4.25
by Jelmer Vernooij
Add paths argument to .unversion. |
193 |
tree.unversion(['foo']) |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
194 |
tree.add(['foo'], [b'foo-id']) |
195 |
self.assertEqual(b'foo-id', tree.path2id('foo')) |
|
|
2323.4.1
by Robert Collins
dirstate correctness: allow adding paths present in the basis. |
196 |
|
197 |
def test_add_present_in_basis(self): |
|
198 |
# adding a path that was present in the basis should work.
|
|
199 |
tree = self.make_branch_and_tree('.') |
|
200 |
self.build_tree(['foo']) |
|
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
201 |
tree.add(['foo']) |
202 |
tree.commit('add foo') |
|
|
6809.4.25
by Jelmer Vernooij
Add paths argument to .unversion. |
203 |
tree.unversion(['foo']) |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
204 |
tree.add(['foo']) |
205 |
self.assertTrue(tree.has_filename('foo')) |
|
206 |
||
207 |
def test_add_present_in_basis_with_file_ids(self): |
|
208 |
# adding a path that was present in the basis should work.
|
|
209 |
tree = self.make_branch_and_tree('.') |
|
210 |
if not tree.supports_setting_file_ids(): |
|
|
6819.1.3
by Jelmer Vernooij
Use self.skipTest. |
211 |
self.skipTest("tree does not support setting file ids") |
|
6745.1.1
by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking |
212 |
self.build_tree(['foo']) |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
213 |
tree.add(['foo'], [b'foo-id']) |
|
2323.4.1
by Robert Collins
dirstate correctness: allow adding paths present in the basis. |
214 |
tree.commit('add foo') |
|
6809.4.25
by Jelmer Vernooij
Add paths argument to .unversion. |
215 |
tree.unversion(['foo']) |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
216 |
tree.add(['foo'], [b'foo-id']) |
217 |
self.assertEqual(b'foo-id', tree.path2id('foo')) |