79
def apply_inventory_WT(self, basis, delta):
80
"""Apply delta to basis and return the result.
82
This sets the tree state to be basis, and then calls apply_inventory_delta.
84
:param basis: An inventory to be used as the basis.
85
:param delta: The inventory delta to apply:
86
:return: An inventory resulting from the application.
88
control = self.make_bzrdir('tree', format=self.format._matchingbzrdir)
89
control.create_repository()
90
control.create_branch()
91
tree = self.format.initialize(control)
94
tree._write_inventory(basis)
97
# Fresh object, reads disk again.
98
tree = tree.bzrdir.open_workingtree()
101
tree.apply_inventory_delta(delta)
104
# reload tree - ensure we get what was written.
105
tree = tree.bzrdir.open_workingtree()
107
self.addCleanup(tree.unlock)
108
# One could add 'tree._validate' here but that would cause 'early' failues
109
# as far as higher level code is concerned. Possibly adding an
110
# expect_fail parameter to this function and if that is False then do a
112
return tree.inventory
74
115
def apply_inventory_WT_basis(self, basis, delta):
75
116
"""Apply delta to basis and return the result.
236
277
inv2 = self.get_empty_inventory(inv)
237
278
self.assertEqual([], inv2._make_delta(inv))
280
def test_None_file_id(self):
281
inv = self.get_empty_inventory()
282
dir1 = inventory.InventoryDirectory(None, 'dir1', inv.root.file_id)
283
dir1.revision = 'result'
284
delta = [(None, u'dir1', None, dir1)]
285
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
288
def test_unicode_file_id(self):
289
inv = self.get_empty_inventory()
290
dir1 = inventory.InventoryDirectory(u'dirid', 'dir1', inv.root.file_id)
291
dir1.revision = 'result'
292
delta = [(None, u'dir1', dir1.file_id, dir1)]
293
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
239
296
def test_repeated_file_id(self):
240
297
inv = self.get_empty_inventory()
241
298
file1 = inventory.InventoryFile('id', 'path1', inv.root.file_id)
296
353
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
356
def test_mismatched_new_path_entry_None(self):
357
inv = self.get_empty_inventory()
358
delta = [(None, u'path', 'id', None)]
359
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
362
def test_mismatched_new_path_None_entry(self):
363
inv = self.get_empty_inventory()
364
file1 = inventory.InventoryFile('id1', 'path', inv.root.file_id)
365
file1.revision = 'result'
368
delta = [(u"path", None, 'id1', file1)]
369
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
299
372
def test_parent_is_not_directory(self):
300
373
inv = self.get_empty_inventory()
301
374
file1 = inventory.InventoryFile('id1', 'path', inv.root.file_id)
321
394
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
397
def test_new_parent_path_has_wrong_id(self):
398
inv = self.get_empty_inventory()
399
parent1 = inventory.InventoryDirectory('p-1', 'dir', inv.root.file_id)
400
parent1.revision = 'result'
401
parent2 = inventory.InventoryDirectory('p-2', 'dir2', inv.root.file_id)
402
parent2.revision = 'result'
403
file1 = inventory.InventoryFile('id', 'path', 'p-2')
404
file1.revision = 'result'
409
# This delta claims that file1 is at dir/path, but actually its at
410
# dir2/path if you follow the inventory parent structure.
411
delta = [(None, u'dir/path', 'id', file1)]
412
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
415
def test_old_parent_path_is_wrong(self):
416
inv = self.get_empty_inventory()
417
parent1 = inventory.InventoryDirectory('p-1', 'dir', inv.root.file_id)
418
parent1.revision = 'result'
419
parent2 = inventory.InventoryDirectory('p-2', 'dir2', inv.root.file_id)
420
parent2.revision = 'result'
421
file1 = inventory.InventoryFile('id', 'path', 'p-2')
422
file1.revision = 'result'
428
# This delta claims that file1 was at dir/path, but actually it was at
429
# dir2/path if you follow the inventory parent structure.
430
delta = [(u'dir/path', None, 'id', None)]
431
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
434
def test_old_parent_path_is_for_other_id(self):
435
inv = self.get_empty_inventory()
436
parent1 = inventory.InventoryDirectory('p-1', 'dir', inv.root.file_id)
437
parent1.revision = 'result'
438
parent2 = inventory.InventoryDirectory('p-2', 'dir2', inv.root.file_id)
439
parent2.revision = 'result'
440
file1 = inventory.InventoryFile('id', 'path', 'p-2')
441
file1.revision = 'result'
444
file2 = inventory.InventoryFile('id2', 'path', 'p-1')
445
file2.revision = 'result'
452
# This delta claims that file1 was at dir/path, but actually it was at
453
# dir2/path if you follow the inventory parent structure. At dir/path
454
# is another entry we should not delete.
455
delta = [(u'dir/path', None, 'id', None)]
456
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
459
def test_add_existing_id_new_path(self):
460
inv = self.get_empty_inventory()
461
parent1 = inventory.InventoryDirectory('p-1', 'dir1', inv.root.file_id)
462
parent1.revision = 'result'
463
parent2 = inventory.InventoryDirectory('p-1', 'dir2', inv.root.file_id)
464
parent2.revision = 'result'
466
delta = [(None, u'dir2', 'p-1', parent2)]
467
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
470
def test_add_new_id_existing_path(self):
471
inv = self.get_empty_inventory()
472
parent1 = inventory.InventoryDirectory('p-1', 'dir1', inv.root.file_id)
473
parent1.revision = 'result'
474
parent2 = inventory.InventoryDirectory('p-2', 'dir1', inv.root.file_id)
475
parent2.revision = 'result'
477
delta = [(None, u'dir1', 'p-2', parent2)]
478
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
481
def test_remove_dir_leaving_dangling_child(self):
482
inv = self.get_empty_inventory()
483
dir1 = inventory.InventoryDirectory('p-1', 'dir1', inv.root.file_id)
484
dir1.revision = 'result'
485
dir2 = inventory.InventoryDirectory('p-2', 'child1', 'p-1')
486
dir2.revision = 'result'
487
dir3 = inventory.InventoryDirectory('p-3', 'child2', 'p-1')
488
dir3.revision = 'result'
492
delta = [(u'dir1', None, 'p-1', None),
493
(u'dir1/child2', None, 'p-3', None)]
494
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
325
498
class TestInventoryEntry(TestCase):