20
20
from bzrlib.branch import Branch
21
21
import bzrlib.errors as errors
22
22
from bzrlib.diff import internal_diff
23
from bzrlib.inventory import Inventory, ROOT_ID
23
from bzrlib.inventory import (Inventory, ROOT_ID, InventoryFile,
24
InventoryDirectory, InventoryEntry)
24
25
import bzrlib.inventory as inventory
25
26
from bzrlib.osutils import has_symlinks, rename, pathjoin
26
27
from bzrlib.tests import TestCase, TestCaseWithTransport
399
400
# TODO: test two inventories with the same file revision
403
class TestDescribeChanges(TestCase):
405
def test_describe_change(self):
406
# we need to test the following change combinations:
412
# renamed/reparented and modified
413
# change kind (perhaps can't be done yet?)
414
# also, merged in combination with all of these?
415
old_a = InventoryFile('a-id', 'a_file', ROOT_ID)
416
old_a.text_sha1 = '123132'
418
new_a = InventoryFile('a-id', 'a_file', ROOT_ID)
419
new_a.text_sha1 = '123132'
422
self.assertChangeDescription('unchanged', old_a, new_a)
425
new_a.text_sha1 = 'abcabc'
426
self.assertChangeDescription('modified', old_a, new_a)
428
self.assertChangeDescription('added', None, new_a)
429
self.assertChangeDescription('removed', old_a, None)
430
# perhaps a bit questionable but seems like the most reasonable thing...
431
self.assertChangeDescription('unchanged', None, None)
433
# in this case it's both renamed and modified; show a rename and
435
new_a.name = 'newfilename'
436
self.assertChangeDescription('modified and renamed', old_a, new_a)
438
# reparenting is 'renaming'
439
new_a.name = old_a.name
440
new_a.parent_id = 'somedir-id'
441
self.assertChangeDescription('modified and renamed', old_a, new_a)
443
# reset the content values so its not modified
444
new_a.text_size = old_a.text_size
445
new_a.text_sha1 = old_a.text_sha1
446
new_a.name = old_a.name
448
new_a.name = 'newfilename'
449
self.assertChangeDescription('renamed', old_a, new_a)
451
# reparenting is 'renaming'
452
new_a.name = old_a.name
453
new_a.parent_id = 'somedir-id'
454
self.assertChangeDescription('renamed', old_a, new_a)
456
def assertChangeDescription(self, expected_change, old_ie, new_ie):
457
change = InventoryEntry.describe_change(old_ie, new_ie)
458
self.assertEqual(expected_change, change)
402
461
class TestExecutable(TestCaseWithTransport):
404
463
def test_stays_executable(self):
494
553
self.failUnless(t2.is_executable(a_id), "'a' lost the execute bit")
495
554
self.failIf(t2.is_executable(b_id), "'b' gained an execute bit")
497
557
class TestRevert(TestCaseWithTransport):
498
559
def test_dangling_id(self):
499
560
wt = self.make_branch_and_tree('b1')
500
561
self.assertEqual(len(wt.inventory), 1)