96
96
serializer = inventory_delta.InventoryDeltaSerializer()
97
97
err = self.assertRaises(
98
98
errors.BzrError, serializer.parse_text_bytes, '')
99
self.assertContainsRe(str(err), 'unknown format')
99
self.assertContainsRe(str(err), 'last line not empty')
101
101
def test_parse_bad_format(self):
102
102
serializer = inventory_delta.InventoryDeltaSerializer()
142
142
'directory', u'', None, 'an-id')
143
143
expected_entry.revision = 'a@e\xc3\xa5ample.com--2004'
144
144
self.assertEqual(
145
('null:', 'entry-version', True, True,
146
[(None, '/', 'an-id', expected_entry)]),
145
('null:', 'entry-version', True, True,
146
[(None, '', 'an-id', expected_entry)]),
149
149
def test_parse_special_revid_not_valid_last_mod(self):
236
236
serializer.parse_text_bytes, lines)
237
237
self.assertContainsRe(str(err), 'Versioned root found')
239
def test_parse_last_line_not_empty(self):
240
"""newpath must start with / if it is not None."""
241
# Trim the trailing newline from a valid serialization
242
lines = root_only_lines[:-1]
243
serializer = inventory_delta.InventoryDeltaSerializer()
244
err = self.assertRaises(errors.BzrError,
245
serializer.parse_text_bytes, lines)
246
self.assertContainsRe(str(err), 'last line not empty')
248
def test_parse_invalid_newpath(self):
249
"""newpath must start with / if it is not None."""
251
lines += "None\x00bad\x00TREE_ROOT\x00\x00version\x00dir\n"
252
serializer = inventory_delta.InventoryDeltaSerializer()
253
err = self.assertRaises(errors.BzrError,
254
serializer.parse_text_bytes, lines)
255
self.assertContainsRe(str(err), 'newpath invalid')
257
def test_parse_invalid_oldpath(self):
258
"""oldpath must start with / if it is not None."""
259
lines = root_only_lines
260
lines += "bad\x00/new\x00file-id\x00\x00version\x00dir\n"
261
serializer = inventory_delta.InventoryDeltaSerializer()
262
err = self.assertRaises(errors.BzrError,
263
serializer.parse_text_bytes, lines)
264
self.assertContainsRe(str(err), 'oldpath invalid')
241
267
class TestSerialization(TestCase):
383
409
serializer.delta_to_lines(NULL_REVISION, 'entry-version', delta))
385
411
def test_to_inventory_root_id_versioned_not_permitted(self):
386
delta = [(None, '/', 'TREE_ROOT', inventory.make_entry(
387
'directory', '', None, 'TREE_ROOT'))]
412
root_entry = inventory.make_entry('directory', '', None, 'TREE_ROOT')
413
root_entry.revision = 'some-version'
414
delta = [(None, '', 'TREE_ROOT', root_entry)]
388
415
serializer = inventory_delta.InventoryDeltaSerializer()
389
416
serializer.require_flags(versioned_root=False, tree_references=True)
390
417
self.assertRaises(
392
419
'new-version', delta)
394
421
def test_to_inventory_root_id_not_versioned(self):
395
delta = [(None, '/', 'an-id', inventory.make_entry(
422
delta = [(None, '', 'an-id', inventory.make_entry(
396
423
'directory', '', None, 'an-id'))]
397
424
serializer = inventory_delta.InventoryDeltaSerializer()
398
425
serializer.require_flags(versioned_root=True, tree_references=True)
405
432
tree_ref = make_entry('tree-reference', 'foo', 'changed-in', 'ref-id')
406
433
tree_ref.reference_revision = 'ref-revision'
409
436
make_entry('directory', '', 'changed-in', 'an-id')),
410
(None, '/foo', 'ref-id', tree_ref)
437
(None, 'foo', 'ref-id', tree_ref)
411
438
# a file that followed the root move
413
440
serializer = inventory_delta.InventoryDeltaSerializer()