289
302
new_rev = s_v5.read_revision_from_string(txt)
290
303
self.assertEqual(props, new_rev.properties)
305
def test_roundtrip_inventory_v7(self):
306
inv = Inventory('tree-root-321', revision_id='rev_outer')
307
inv.add(inventory.TreeReference('nested-id', 'nested', 'tree-root-321',
308
'rev_outer', 'rev_inner'))
309
inv.add(inventory.InventoryFile('file-id', 'file', 'tree-root-321'))
310
inv.add(inventory.InventoryDirectory('dir-id', 'dir',
312
inv.add(inventory.InventoryLink('link-id', 'link', 'tree-root-321'))
313
inv['tree-root-321'].revision = 'rev_outer'
314
inv['dir-id'].revision = 'rev_outer'
315
inv['file-id'].revision = 'rev_outer'
316
inv['link-id'].revision = 'rev_outer'
317
txt = xml7.serializer_v7.write_inventory_to_string(inv)
318
self.assertEqualDiff(_expected_inv_v7, txt)
319
inv2 = xml7.serializer_v7.read_inventory_from_string(txt)
320
self.assertEqual(5, len(inv2))
321
for path, ie in inv.iter_entries():
322
self.assertEqual(ie, inv2[ie.file_id])
324
def test_wrong_format_v7(self):
325
"""Can't accidentally open a file with wrong serializer"""
326
s_v6 = bzrlib.xml6.serializer_v6
327
s_v7 = xml7.serializer_v7
328
self.assertRaises(errors.UnexpectedInventoryFormat,
329
s_v7.read_inventory_from_string, _expected_inv_v5)
330
self.assertRaises(errors.UnexpectedInventoryFormat,
331
s_v6.read_inventory_from_string, _expected_inv_v7)
333
def test_tree_reference(self):
334
s_v5 = bzrlib.xml5.serializer_v5
335
s_v6 = bzrlib.xml6.serializer_v6
336
s_v7 = xml7.serializer_v7
337
inv = Inventory('tree-root-321')
338
inv.add(inventory.TreeReference('nested-id', 'nested', 'tree-root-321',
339
'rev-outer', 'rev-inner'))
340
self.assertRaises(errors.UnsupportedInventoryKind,
341
s_v5.write_inventory_to_string, inv)
342
self.assertRaises(errors.UnsupportedInventoryKind,
343
s_v6.write_inventory_to_string, inv)
344
txt = s_v7.write_inventory_to_string(inv)
345
inv2 = s_v7.read_inventory_from_string(txt)
346
self.assertEqual('tree-root-321', inv2['nested-id'].parent_id)
347
self.assertEqual('rev-outer', inv2['nested-id'].revision)
348
self.assertEqual('rev-inner', inv2['nested-id'].reference_revision)
349
self.assertRaises(errors.UnsupportedInventoryKind,
350
s_v6.read_inventory_from_string,
351
txt.replace('format="7"', 'format="6"'))
352
self.assertRaises(errors.UnsupportedInventoryKind,
353
s_v5.read_inventory_from_string,
354
txt.replace('format="7"', 'format="5"'))
292
356
def test_revision_ids_are_utf8(self):
293
357
"""Parsed revision_ids should all be utf-8 strings, not unicode."""
294
358
s_v5 = bzrlib.xml5.serializer_v5