~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inv.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-05-17 08:50:40 UTC
  • mfrom: (1704.2.18 bzr.mbp.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060517085040-ee6e33957c557fba
(mbp) merge 0.8 fixes; fix #32587

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 
400
401
 
401
402
 
 
403
class TestDescribeChanges(TestCase):
 
404
 
 
405
    def test_describe_change(self):
 
406
        # we need to test the following change combinations:
 
407
        # rename
 
408
        # reparent
 
409
        # modify
 
410
        # gone
 
411
        # added
 
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'
 
417
        old_a.text_size = 0
 
418
        new_a = InventoryFile('a-id', 'a_file', ROOT_ID)
 
419
        new_a.text_sha1 = '123132'
 
420
        new_a.text_size = 0
 
421
 
 
422
        self.assertChangeDescription('unchanged', old_a, new_a)
 
423
 
 
424
        new_a.text_size = 10
 
425
        new_a.text_sha1 = 'abcabc'
 
426
        self.assertChangeDescription('modified', old_a, new_a)
 
427
 
 
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)
 
432
 
 
433
        # in this case it's both renamed and modified; show a rename and 
 
434
        # modification:
 
435
        new_a.name = 'newfilename'
 
436
        self.assertChangeDescription('modified and renamed', old_a, new_a)
 
437
 
 
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)
 
442
 
 
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
 
447
 
 
448
        new_a.name = 'newfilename'
 
449
        self.assertChangeDescription('renamed', old_a, new_a)
 
450
 
 
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)
 
455
 
 
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)
 
459
 
 
460
 
402
461
class TestExecutable(TestCaseWithTransport):
403
462
 
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")
496
555
 
 
556
 
497
557
class TestRevert(TestCaseWithTransport):
 
558
 
498
559
    def test_dangling_id(self):
499
560
        wt = self.make_branch_and_tree('b1')
500
561
        self.assertEqual(len(wt.inventory), 1)
504
565
        os.unlink('b1/a')
505
566
        wt.revert([])
506
567
        self.assertEqual(len(wt.inventory), 1)
507
 
 
508