bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
1 |
# Copyright (C) 2008, 2009 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
|
|
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
17 |
"""Tests for bzrlib.inventory_delta.
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
18 |
|
19 |
See doc/developer/inventory.txt for more information.
|
|
20 |
"""
|
|
21 |
||
22 |
from cStringIO import StringIO |
|
23 |
||
24 |
from bzrlib import ( |
|
25 |
errors, |
|
26 |
inventory, |
|
27 |
inventory_delta, |
|
28 |
)
|
|
29 |
from bzrlib.inventory import Inventory |
|
30 |
from bzrlib.revision import NULL_REVISION |
|
31 |
from bzrlib.tests import TestCase |
|
32 |
||
33 |
### DO NOT REFLOW THESE TEXTS. NEW LINES ARE SIGNIFICANT. ###
|
|
34 |
empty_lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
35 |
parent: null:
|
|
36 |
version: null:
|
|
37 |
versioned_root: true
|
|
38 |
tree_references: true
|
|
39 |
"""
|
|
40 |
||
41 |
root_only_lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
42 |
parent: null:
|
|
43 |
version: entry-version
|
|
44 |
versioned_root: true
|
|
45 |
tree_references: true
|
|
|
4205.5.3
by Andrew Bennetts
Include oldpath in the the serialised delta |
46 |
None\x00/\x00an-id\x00\x00a@e\xc3\xa5ample.com--2004\x00dir |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
47 |
"""
|
48 |
||
49 |
||
50 |
root_change_lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
51 |
parent: entry-version
|
|
52 |
version: changed-root
|
|
53 |
versioned_root: true
|
|
54 |
tree_references: true
|
|
55 |
/\x00an-id\x00\x00different-version\x00dir |
|
56 |
"""
|
|
57 |
||
58 |
corrupt_parent_lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
59 |
parent: entry-version
|
|
60 |
version: changed-root
|
|
61 |
versioned_root: false
|
|
62 |
tree_references: false
|
|
63 |
/\x00an-id\x00\x00different-version\x00dir |
|
64 |
"""
|
|
65 |
||
66 |
root_only_unversioned = """format: bzr inventory delta v1 (bzr 1.14) |
|
67 |
parent: null:
|
|
68 |
version: entry-version
|
|
69 |
versioned_root: false
|
|
70 |
tree_references: false
|
|
|
4205.5.3
by Andrew Bennetts
Include oldpath in the the serialised delta |
71 |
None\x00/\x00TREE_ROOT\x00\x00null:\x00dir |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
72 |
"""
|
73 |
||
74 |
reference_lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
75 |
parent: null:
|
|
76 |
version: entry-version
|
|
77 |
versioned_root: true
|
|
78 |
tree_references: true
|
|
|
4205.5.3
by Andrew Bennetts
Include oldpath in the the serialised delta |
79 |
None\x00/\x00TREE_ROOT\x00\x00a@e\xc3\xa5ample.com--2004\x00dir |
80 |
None\x00/foo\x00id\x00TREE_ROOT\x00changed\x00tree\x00subtree-version |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
81 |
"""
|
82 |
||
83 |
change_tree_lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
84 |
parent: entry-version
|
|
85 |
version: change-tree
|
|
86 |
versioned_root: false
|
|
87 |
tree_references: false
|
|
88 |
/foo\x00id\x00TREE_ROOT\x00changed-twice\x00tree\x00subtree-version2 |
|
89 |
"""
|
|
90 |
||
91 |
||
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
92 |
class TestDeserialization(TestCase): |
93 |
"""Test InventoryDeltaSerializer.parse_text_bytes.""" |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
94 |
|
95 |
def test_parse_no_bytes(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
96 |
serializer = inventory_delta.InventoryDeltaSerializer() |
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
97 |
err = self.assertRaises( |
98 |
errors.BzrError, serializer.parse_text_bytes, '') |
|
99 |
self.assertContainsRe(str(err), 'unknown format') |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
100 |
|
101 |
def test_parse_bad_format(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
102 |
serializer = inventory_delta.InventoryDeltaSerializer() |
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
103 |
err = self.assertRaises(errors.BzrError, |
104 |
serializer.parse_text_bytes, 'format: foo\n') |
|
105 |
self.assertContainsRe(str(err), 'unknown format') |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
106 |
|
107 |
def test_parse_no_parent(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
108 |
serializer = inventory_delta.InventoryDeltaSerializer() |
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
109 |
err = self.assertRaises(errors.BzrError, |
110 |
serializer.parse_text_bytes, |
|
111 |
'format: bzr inventory delta v1 (bzr 1.14)\n') |
|
112 |
self.assertContainsRe(str(err), 'missing parent: marker') |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
113 |
|
114 |
def test_parse_no_version(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
115 |
serializer = inventory_delta.InventoryDeltaSerializer() |
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
116 |
err = self.assertRaises(errors.BzrError, |
117 |
serializer.parse_text_bytes, |
|
118 |
'format: bzr inventory delta v1 (bzr 1.14)\n' |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
119 |
'parent: null:\n') |
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
120 |
self.assertContainsRe(str(err), 'missing version: marker') |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
121 |
|
122 |
def test_parse_duplicate_key_errors(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
123 |
serializer = inventory_delta.InventoryDeltaSerializer() |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
124 |
double_root_lines = \ |
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
125 |
"""format: bzr inventory delta v1 (bzr 1.14)
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
126 |
parent: null:
|
127 |
version: null:
|
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
128 |
versioned_root: true
|
129 |
tree_references: true
|
|
130 |
None\x00/\x00an-id\x00\x00a@e\xc3\xa5ample.com--2004\x00dir\x00\x00
|
|
131 |
None\x00/\x00an-id\x00\x00a@e\xc3\xa5ample.com--2004\x00dir\x00\x00
|
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
132 |
"""
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
133 |
err = self.assertRaises(errors.BzrError, |
134 |
serializer.parse_text_bytes, double_root_lines) |
|
135 |
self.assertContainsRe(str(err), 'duplicate file id') |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
136 |
|
137 |
def test_parse_versioned_root_only(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
138 |
serializer = inventory_delta.InventoryDeltaSerializer() |
139 |
serializer.require_flags(versioned_root=True, tree_references=True) |
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
140 |
parse_result = serializer.parse_text_bytes(root_only_lines) |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
141 |
expected_entry = inventory.make_entry( |
142 |
'directory', u'', None, 'an-id') |
|
143 |
expected_entry.revision = 'a@e\xc3\xa5ample.com--2004' |
|
144 |
self.assertEqual( |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
145 |
('null:', 'entry-version', True, True, |
146 |
[(None, '/', 'an-id', expected_entry)]), |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
147 |
parse_result) |
148 |
||
149 |
def test_parse_special_revid_not_valid_last_mod(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
150 |
serializer = inventory_delta.InventoryDeltaSerializer() |
151 |
serializer.require_flags(versioned_root=False, tree_references=True) |
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
152 |
root_only_lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
153 |
parent: null:
|
154 |
version: null:
|
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
155 |
versioned_root: false
|
156 |
tree_references: true
|
|
157 |
None\x00/\x00TREE_ROOT\x00\x00null:\x00dir\x00\x00 |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
158 |
"""
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
159 |
err = self.assertRaises(errors.BzrError, |
160 |
serializer.parse_text_bytes, root_only_lines) |
|
161 |
self.assertContainsRe(str(err), 'special revisionid found') |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
162 |
|
163 |
def test_parse_versioned_root_versioned_disabled(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
164 |
serializer = inventory_delta.InventoryDeltaSerializer() |
165 |
serializer.require_flags(versioned_root=False, tree_references=True) |
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
166 |
root_only_lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
167 |
parent: null:
|
168 |
version: null:
|
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
169 |
versioned_root: false
|
170 |
tree_references: true
|
|
171 |
None\x00/\x00TREE_ROOT\x00\x00a@e\xc3\xa5ample.com--2004\x00dir\x00\x00 |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
172 |
"""
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
173 |
err = self.assertRaises(errors.BzrError, |
174 |
serializer.parse_text_bytes, root_only_lines) |
|
175 |
self.assertContainsRe(str(err), 'Versioned root found') |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
176 |
|
177 |
def test_parse_unique_root_id_root_versioned_disabled(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
178 |
serializer = inventory_delta.InventoryDeltaSerializer() |
179 |
serializer.require_flags(versioned_root=False, tree_references=True) |
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
180 |
root_only_lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
181 |
parent: null:
|
182 |
version: null:
|
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
183 |
versioned_root: false
|
184 |
tree_references: true
|
|
185 |
None\x00/\x00an-id\x00\x00null:\x00dir\x00\x00 |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
186 |
"""
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
187 |
err = self.assertRaises(errors.BzrError, |
188 |
serializer.parse_text_bytes, root_only_lines) |
|
189 |
self.assertContainsRe(str(err), 'Versioned root found') |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
190 |
|
191 |
def test_parse_unversioned_root_versioning_enabled(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
192 |
serializer = inventory_delta.InventoryDeltaSerializer() |
193 |
serializer.require_flags(versioned_root=True, tree_references=True) |
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
194 |
err = self.assertRaises(errors.BzrError, |
195 |
serializer.parse_text_bytes, root_only_unversioned) |
|
196 |
self.assertContainsRe( |
|
197 |
str(err), 'serialized versioned_root flag is wrong: False') |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
198 |
|
199 |
def test_parse_tree_when_disabled(self): |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
200 |
serializer = inventory_delta.InventoryDeltaSerializer() |
201 |
serializer.require_flags(versioned_root=True, tree_references=False) |
|
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
202 |
err = self.assertRaises(errors.BzrError, |
203 |
serializer.parse_text_bytes, reference_lines) |
|
204 |
self.assertContainsRe( |
|
205 |
str(err), 'serialized tree_references flag is wrong: True') |
|
206 |
||
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
207 |
def test_parse_tree_when_header_disallows(self): |
208 |
# A deserializer that allows tree_references to be set or unset.
|
|
209 |
serializer = inventory_delta.InventoryDeltaSerializer() |
|
210 |
# A serialised inventory delta with a header saying no tree refs, but
|
|
211 |
# that has a tree ref in its content.
|
|
212 |
lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
213 |
parent: null:
|
|
214 |
version: entry-version
|
|
215 |
versioned_root: false
|
|
216 |
tree_references: false
|
|
217 |
None\x00/foo\x00id\x00TREE_ROOT\x00changed\x00tree\x00subtree-version |
|
218 |
"""
|
|
219 |
err = self.assertRaises(errors.BzrError, |
|
220 |
serializer.parse_text_bytes, lines) |
|
221 |
self.assertContainsRe(str(err), 'Tree reference found') |
|
222 |
||
223 |
def test_parse_versioned_root_when_header_disallows(self): |
|
224 |
# A deserializer that allows tree_references to be set or unset.
|
|
225 |
serializer = inventory_delta.InventoryDeltaSerializer() |
|
226 |
# A serialised inventory delta with a header saying no tree refs, but
|
|
227 |
# that has a tree ref in its content.
|
|
228 |
lines = """format: bzr inventory delta v1 (bzr 1.14) |
|
229 |
parent: null:
|
|
230 |
version: entry-version
|
|
231 |
versioned_root: false
|
|
232 |
tree_references: false
|
|
233 |
None\x00/\x00TREE_ROOT\x00\x00a@e\xc3\xa5ample.com--2004\x00dir |
|
234 |
"""
|
|
235 |
err = self.assertRaises(errors.BzrError, |
|
236 |
serializer.parse_text_bytes, lines) |
|
237 |
self.assertContainsRe(str(err), 'Versioned root found') |
|
238 |
||
239 |
||
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
240 |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
241 |
class TestSerialization(TestCase): |
|
4205.5.4
by Andrew Bennetts
Fix many tests in test_inventory_delta to actually test what they intended to test. |
242 |
"""Tests for InventoryDeltaSerializer.delta_to_lines.""" |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
243 |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
244 |
def test_empty_delta_to_lines(self): |
245 |
old_inv = Inventory(None) |
|
246 |
new_inv = Inventory(None) |
|
247 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
248 |
serializer = inventory_delta.InventoryDeltaSerializer() |
249 |
serializer.require_flags(True, True) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
250 |
self.assertEqual(StringIO(empty_lines).readlines(), |
251 |
serializer.delta_to_lines(NULL_REVISION, NULL_REVISION, delta)) |
|
252 |
||
253 |
def test_root_only_to_lines(self): |
|
254 |
old_inv = Inventory(None) |
|
255 |
new_inv = Inventory(None) |
|
256 |
root = new_inv.make_entry('directory', '', None, 'an-id') |
|
257 |
root.revision = 'a@e\xc3\xa5ample.com--2004' |
|
258 |
new_inv.add(root) |
|
259 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
260 |
serializer = inventory_delta.InventoryDeltaSerializer() |
261 |
serializer.require_flags(versioned_root=True, tree_references=True) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
262 |
self.assertEqual(StringIO(root_only_lines).readlines(), |
263 |
serializer.delta_to_lines(NULL_REVISION, 'entry-version', delta)) |
|
264 |
||
265 |
def test_unversioned_root(self): |
|
266 |
old_inv = Inventory(None) |
|
267 |
new_inv = Inventory(None) |
|
268 |
root = new_inv.make_entry('directory', '', None, 'TREE_ROOT') |
|
269 |
new_inv.add(root) |
|
270 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
271 |
serializer = inventory_delta.InventoryDeltaSerializer() |
272 |
serializer.require_flags(False, False) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
273 |
self.assertEqual(StringIO(root_only_unversioned).readlines(), |
274 |
serializer.delta_to_lines(NULL_REVISION, 'entry-version', delta)) |
|
275 |
||
276 |
def test_unversioned_non_root_errors(self): |
|
277 |
old_inv = Inventory(None) |
|
278 |
new_inv = Inventory(None) |
|
279 |
root = new_inv.make_entry('directory', '', None, 'TREE_ROOT') |
|
280 |
root.revision = 'a@e\xc3\xa5ample.com--2004' |
|
281 |
new_inv.add(root) |
|
282 |
non_root = new_inv.make_entry('directory', 'foo', root.file_id, 'id') |
|
283 |
new_inv.add(non_root) |
|
284 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
285 |
serializer = inventory_delta.InventoryDeltaSerializer() |
286 |
serializer.require_flags(versioned_root=True, tree_references=True) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
287 |
err = self.assertRaises(errors.BzrError, |
288 |
serializer.delta_to_lines, NULL_REVISION, 'entry-version', delta) |
|
289 |
self.assertEqual(str(err), 'no version for fileid id') |
|
290 |
||
291 |
def test_richroot_unversioned_root_errors(self): |
|
292 |
old_inv = Inventory(None) |
|
293 |
new_inv = Inventory(None) |
|
294 |
root = new_inv.make_entry('directory', '', None, 'TREE_ROOT') |
|
295 |
new_inv.add(root) |
|
296 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
297 |
serializer = inventory_delta.InventoryDeltaSerializer() |
298 |
serializer.require_flags(versioned_root=True, tree_references=True) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
299 |
err = self.assertRaises(errors.BzrError, |
300 |
serializer.delta_to_lines, NULL_REVISION, 'entry-version', delta) |
|
301 |
self.assertEqual(str(err), 'no version for fileid TREE_ROOT') |
|
302 |
||
303 |
def test_nonrichroot_versioned_root_errors(self): |
|
304 |
old_inv = Inventory(None) |
|
305 |
new_inv = Inventory(None) |
|
306 |
root = new_inv.make_entry('directory', '', None, 'TREE_ROOT') |
|
307 |
root.revision = 'a@e\xc3\xa5ample.com--2004' |
|
308 |
new_inv.add(root) |
|
309 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
310 |
serializer = inventory_delta.InventoryDeltaSerializer() |
311 |
serializer.require_flags(versioned_root=False, tree_references=True) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
312 |
err = self.assertRaises(errors.BzrError, |
313 |
serializer.delta_to_lines, NULL_REVISION, 'entry-version', delta) |
|
314 |
self.assertEqual(str(err), 'Version present for / in TREE_ROOT') |
|
315 |
||
316 |
def test_nonrichroot_non_TREE_ROOT_id_errors(self): |
|
317 |
old_inv = Inventory(None) |
|
318 |
new_inv = Inventory(None) |
|
319 |
root = new_inv.make_entry('directory', '', None, 'my-rich-root-id') |
|
320 |
new_inv.add(root) |
|
321 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
322 |
serializer = inventory_delta.InventoryDeltaSerializer() |
323 |
serializer.require_flags(versioned_root=False, tree_references=True) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
324 |
err = self.assertRaises(errors.BzrError, |
325 |
serializer.delta_to_lines, NULL_REVISION, 'entry-version', delta) |
|
326 |
self.assertEqual( |
|
327 |
str(err), 'file_id my-rich-root-id is not TREE_ROOT for /') |
|
328 |
||
329 |
def test_unknown_kind_errors(self): |
|
330 |
old_inv = Inventory(None) |
|
331 |
new_inv = Inventory(None) |
|
332 |
root = new_inv.make_entry('directory', '', None, 'my-rich-root-id') |
|
333 |
root.revision = 'changed' |
|
334 |
new_inv.add(root) |
|
335 |
non_root = new_inv.make_entry('directory', 'foo', root.file_id, 'id') |
|
336 |
non_root.revision = 'changed' |
|
337 |
non_root.kind = 'strangelove' |
|
338 |
new_inv.add(non_root) |
|
339 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
340 |
serializer = inventory_delta.InventoryDeltaSerializer() |
341 |
serializer.require_flags(True, True) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
342 |
# we expect keyerror because there is little value wrapping this.
|
343 |
# This test aims to prove that it errors more than how it errors.
|
|
344 |
err = self.assertRaises(KeyError, |
|
345 |
serializer.delta_to_lines, NULL_REVISION, 'entry-version', delta) |
|
346 |
self.assertEqual(('strangelove',), err.args) |
|
347 |
||
348 |
def test_tree_reference_disabled(self): |
|
349 |
old_inv = Inventory(None) |
|
350 |
new_inv = Inventory(None) |
|
351 |
root = new_inv.make_entry('directory', '', None, 'TREE_ROOT') |
|
352 |
root.revision = 'a@e\xc3\xa5ample.com--2004' |
|
353 |
new_inv.add(root) |
|
354 |
non_root = new_inv.make_entry( |
|
355 |
'tree-reference', 'foo', root.file_id, 'id') |
|
356 |
non_root.revision = 'changed' |
|
357 |
non_root.reference_revision = 'subtree-version' |
|
358 |
new_inv.add(non_root) |
|
359 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
360 |
serializer = inventory_delta.InventoryDeltaSerializer() |
361 |
serializer.require_flags(versioned_root=True, tree_references=False) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
362 |
# we expect keyerror because there is little value wrapping this.
|
363 |
# This test aims to prove that it errors more than how it errors.
|
|
364 |
err = self.assertRaises(KeyError, |
|
365 |
serializer.delta_to_lines, NULL_REVISION, 'entry-version', delta) |
|
366 |
self.assertEqual(('tree-reference',), err.args) |
|
367 |
||
368 |
def test_tree_reference_enabled(self): |
|
369 |
old_inv = Inventory(None) |
|
370 |
new_inv = Inventory(None) |
|
371 |
root = new_inv.make_entry('directory', '', None, 'TREE_ROOT') |
|
372 |
root.revision = 'a@e\xc3\xa5ample.com--2004' |
|
373 |
new_inv.add(root) |
|
374 |
non_root = new_inv.make_entry( |
|
375 |
'tree-reference', 'foo', root.file_id, 'id') |
|
376 |
non_root.revision = 'changed' |
|
377 |
non_root.reference_revision = 'subtree-version' |
|
378 |
new_inv.add(non_root) |
|
379 |
delta = new_inv._make_delta(old_inv) |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
380 |
serializer = inventory_delta.InventoryDeltaSerializer() |
381 |
serializer.require_flags(versioned_root=True, tree_references=True) |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
382 |
self.assertEqual(StringIO(reference_lines).readlines(), |
383 |
serializer.delta_to_lines(NULL_REVISION, 'entry-version', delta)) |
|
384 |
||
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
385 |
def test_to_inventory_root_id_versioned_not_permitted(self): |
386 |
delta = [(None, '/', 'TREE_ROOT', inventory.make_entry( |
|
387 |
'directory', '', None, 'TREE_ROOT'))] |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
388 |
serializer = inventory_delta.InventoryDeltaSerializer() |
389 |
serializer.require_flags(versioned_root=False, tree_references=True) |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
390 |
self.assertRaises( |
391 |
errors.BzrError, serializer.delta_to_lines, 'old-version', |
|
392 |
'new-version', delta) |
|
393 |
||
394 |
def test_to_inventory_root_id_not_versioned(self): |
|
395 |
delta = [(None, '/', 'an-id', inventory.make_entry( |
|
396 |
'directory', '', None, 'an-id'))] |
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
397 |
serializer = inventory_delta.InventoryDeltaSerializer() |
398 |
serializer.require_flags(versioned_root=True, tree_references=True) |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
399 |
self.assertRaises( |
400 |
errors.BzrError, serializer.delta_to_lines, 'old-version', |
|
401 |
'new-version', delta) |
|
402 |
||
403 |
def test_to_inventory_has_tree_not_meant_to(self): |
|
404 |
make_entry = inventory.make_entry |
|
405 |
tree_ref = make_entry('tree-reference', 'foo', 'changed-in', 'ref-id') |
|
406 |
tree_ref.reference_revision = 'ref-revision' |
|
407 |
delta = [ |
|
408 |
(None, '/', 'an-id', |
|
409 |
make_entry('directory', '', 'changed-in', 'an-id')), |
|
410 |
(None, '/foo', 'ref-id', tree_ref) |
|
411 |
# a file that followed the root move
|
|
412 |
]
|
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
413 |
serializer = inventory_delta.InventoryDeltaSerializer() |
414 |
serializer.require_flags(versioned_root=True, tree_references=True) |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
415 |
self.assertRaises(errors.BzrError, serializer.delta_to_lines, |
416 |
'old-version', 'new-version', delta) |
|
417 |
||
418 |
def test_to_inventory_torture(self): |
|
419 |
def make_entry(kind, name, parent_id, file_id, **attrs): |
|
420 |
entry = inventory.make_entry(kind, name, parent_id, file_id) |
|
421 |
for name, value in attrs.items(): |
|
422 |
setattr(entry, name, value) |
|
423 |
return entry |
|
424 |
# this delta is crafted to have all the following:
|
|
425 |
# - deletes
|
|
426 |
# - renamed roots
|
|
427 |
# - deep dirs
|
|
428 |
# - files moved after parent dir was renamed
|
|
429 |
# - files with and without exec bit
|
|
430 |
delta = [ |
|
431 |
# new root:
|
|
432 |
(None, '', 'new-root-id', |
|
433 |
make_entry('directory', '', None, 'new-root-id', |
|
434 |
revision='changed-in')), |
|
435 |
# an old root:
|
|
436 |
('', 'old-root', 'TREE_ROOT', |
|
437 |
make_entry('directory', 'subdir-now', 'new-root-id', |
|
438 |
'TREE_ROOT', revision='moved-root')), |
|
439 |
# a file that followed the root move
|
|
440 |
('under-old-root', 'old-root/under-old-root', 'moved-id', |
|
441 |
make_entry('file', 'under-old-root', 'TREE_ROOT', 'moved-id', |
|
442 |
revision='old-rev', executable=False, text_size=30, |
|
443 |
text_sha1='some-sha')), |
|
444 |
# a deleted path
|
|
445 |
('old-file', None, 'deleted-id', None), |
|
446 |
# a tree reference moved to the new root
|
|
447 |
('ref', 'ref', 'ref-id', |
|
448 |
make_entry('tree-reference', 'ref', 'new-root-id', 'ref-id', |
|
449 |
reference_revision='tree-reference-id', |
|
450 |
revision='new-rev')), |
|
451 |
# a symlink now in a deep dir
|
|
452 |
('dir/link', 'old-root/dir/link', 'link-id', |
|
453 |
make_entry('symlink', 'link', 'deep-id', 'link-id', |
|
454 |
symlink_target='target', revision='new-rev')), |
|
455 |
# a deep dir
|
|
456 |
('dir', 'old-root/dir', 'deep-id', |
|
457 |
make_entry('directory', 'dir', 'TREE_ROOT', 'deep-id', |
|
458 |
revision='new-rev')), |
|
459 |
# a file with an exec bit set
|
|
460 |
(None, 'configure', 'exec-id', |
|
461 |
make_entry('file', 'configure', 'new-root-id', 'exec-id', |
|
462 |
executable=True, text_size=30, text_sha1='some-sha', |
|
463 |
revision='old-rev')), |
|
464 |
]
|
|
|
4476.3.4
by Andrew Bennetts
Network serialisation, and most tests passing with InterDifferingSerializer commented out. |
465 |
serializer = inventory_delta.InventoryDeltaSerializer() |
466 |
serializer.require_flags(versioned_root=True, tree_references=True) |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
467 |
lines = serializer.delta_to_lines(NULL_REVISION, 'something', delta) |
468 |
expected = """format: bzr inventory delta v1 (bzr 1.14) |
|
469 |
parent: null:
|
|
470 |
version: something
|
|
471 |
versioned_root: true
|
|
472 |
tree_references: true
|
|
|
4205.5.3
by Andrew Bennetts
Include oldpath in the the serialised delta |
473 |
/\x00/old-root\x00TREE_ROOT\x00new-root-id\x00moved-root\x00dir |
474 |
/dir\x00/old-root/dir\x00deep-id\x00TREE_ROOT\x00new-rev\x00dir |
|
475 |
/dir/link\x00/old-root/dir/link\x00link-id\x00deep-id\x00new-rev\x00link\x00target |
|
476 |
/old-file\x00None\x00deleted-id\x00\x00null:\x00deleted\x00\x00 |
|
477 |
/ref\x00/ref\x00ref-id\x00new-root-id\x00new-rev\x00tree\x00tree-reference-id |
|
478 |
/under-old-root\x00/old-root/under-old-root\x00moved-id\x00TREE_ROOT\x00old-rev\x00file\x0030\x00\x00some-sha |
|
479 |
None\x00/\x00new-root-id\x00\x00changed-in\x00dir |
|
480 |
None\x00/configure\x00exec-id\x00new-root-id\x00old-rev\x00file\x0030\x00Y\x00some-sha |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
481 |
"""
|
|
4205.5.7
by Andrew Bennetts
Fix nits in spelling and naming. |
482 |
serialized = ''.join(lines) |
483 |
self.assertIsInstance(serialized, str) |
|
484 |
self.assertEqual(expected, serialized) |
|
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
485 |
|
486 |
||
487 |
class TestContent(TestCase): |
|
|
4205.5.5
by Andrew Bennetts
Reorganise tests a little. |
488 |
"""Test serialization of the content part of a line.""" |
|
4205.5.1
by Andrew Bennetts
Initial stab at adapting Robert's journalled_inventory serialisation into inventory_delta serialisation. |
489 |
|
490 |
def test_dir(self): |
|
491 |
entry = inventory.make_entry('directory', 'a dir', None) |
|
492 |
self.assertEqual('dir', inventory_delta._directory_content(entry)) |
|
493 |
||
494 |
def test_file_0_short_sha(self): |
|
495 |
file_entry = inventory.make_entry('file', 'a file', None, 'file-id') |
|
496 |
file_entry.text_sha1 = '' |
|
497 |
file_entry.text_size = 0 |
|
498 |
self.assertEqual('file\x000\x00\x00', |
|
499 |
inventory_delta._file_content(file_entry)) |
|
500 |
||
501 |
def test_file_10_foo(self): |
|
502 |
file_entry = inventory.make_entry('file', 'a file', None, 'file-id') |
|
503 |
file_entry.text_sha1 = 'foo' |
|
504 |
file_entry.text_size = 10 |
|
505 |
self.assertEqual('file\x0010\x00\x00foo', |
|
506 |
inventory_delta._file_content(file_entry)) |
|
507 |
||
508 |
def test_file_executable(self): |
|
509 |
file_entry = inventory.make_entry('file', 'a file', None, 'file-id') |
|
510 |
file_entry.executable = True |
|
511 |
file_entry.text_sha1 = 'foo' |
|
512 |
file_entry.text_size = 10 |
|
513 |
self.assertEqual('file\x0010\x00Y\x00foo', |
|
514 |
inventory_delta._file_content(file_entry)) |
|
515 |
||
516 |
def test_file_without_size(self): |
|
517 |
file_entry = inventory.make_entry('file', 'a file', None, 'file-id') |
|
518 |
file_entry.text_sha1 = 'foo' |
|
519 |
self.assertRaises(errors.BzrError, |
|
520 |
inventory_delta._file_content, file_entry) |
|
521 |
||
522 |
def test_file_without_sha1(self): |
|
523 |
file_entry = inventory.make_entry('file', 'a file', None, 'file-id') |
|
524 |
file_entry.text_size = 10 |
|
525 |
self.assertRaises(errors.BzrError, |
|
526 |
inventory_delta._file_content, file_entry) |
|
527 |
||
528 |
def test_link_empty_target(self): |
|
529 |
entry = inventory.make_entry('symlink', 'a link', None) |
|
530 |
entry.symlink_target = '' |
|
531 |
self.assertEqual('link\x00', |
|
532 |
inventory_delta._link_content(entry)) |
|
533 |
||
534 |
def test_link_unicode_target(self): |
|
535 |
entry = inventory.make_entry('symlink', 'a link', None) |
|
536 |
entry.symlink_target = ' \xc3\xa5'.decode('utf8') |
|
537 |
self.assertEqual('link\x00 \xc3\xa5', |
|
538 |
inventory_delta._link_content(entry)) |
|
539 |
||
540 |
def test_link_space_target(self): |
|
541 |
entry = inventory.make_entry('symlink', 'a link', None) |
|
542 |
entry.symlink_target = ' ' |
|
543 |
self.assertEqual('link\x00 ', |
|
544 |
inventory_delta._link_content(entry)) |
|
545 |
||
546 |
def test_link_no_target(self): |
|
547 |
entry = inventory.make_entry('symlink', 'a link', None) |
|
548 |
self.assertRaises(errors.BzrError, |
|
549 |
inventory_delta._link_content, entry) |
|
550 |
||
551 |
def test_reference_null(self): |
|
552 |
entry = inventory.make_entry('tree-reference', 'a tree', None) |
|
553 |
entry.reference_revision = NULL_REVISION |
|
554 |
self.assertEqual('tree\x00null:', |
|
555 |
inventory_delta._reference_content(entry)) |
|
556 |
||
557 |
def test_reference_revision(self): |
|
558 |
entry = inventory.make_entry('tree-reference', 'a tree', None) |
|
559 |
entry.reference_revision = 'foo@\xc3\xa5b-lah' |
|
560 |
self.assertEqual('tree\x00foo@\xc3\xa5b-lah', |
|
561 |
inventory_delta._reference_content(entry)) |
|
562 |
||
563 |
def test_reference_no_reference(self): |
|
564 |
entry = inventory.make_entry('tree-reference', 'a tree', None) |
|
565 |
self.assertRaises(errors.BzrError, |
|
566 |
inventory_delta._reference_content, entry) |