~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Vincent Ladeuil
  • Date: 2007-11-14 08:20:26 UTC
  • mfrom: (2974 +trunk)
  • mto: (2990.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 2991.
  • Revision ID: v.ladeuil+lp@free.fr-20071114082026-4d27f52n5r0t82rw
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    osutils,
27
27
    )
28
28
from bzrlib.memorytree import MemoryTree
29
 
from bzrlib.osutils import has_symlinks
30
29
from bzrlib.tests import (
 
30
        SymlinkFeature,
31
31
        TestCase,
32
32
        TestCaseWithTransport,
33
 
        TestSkipped,
34
33
        )
35
34
 
36
35
 
1077
1076
        # The most trivial addition of a symlink when there are no parents and
1078
1077
        # its in the root and all data about the file is supplied
1079
1078
        # bzr doesn't support fake symlinks on windows, yet.
1080
 
        if not has_symlinks():
1081
 
            raise TestSkipped("No symlink support")
 
1079
        self.requireFeature(SymlinkFeature)
1082
1080
        os.symlink('target', 'a link')
1083
1081
        stat = os.lstat('a link')
1084
1082
        expected_entries = [
1394
1392
            state.unlock()
1395
1393
 
1396
1394
 
 
1395
class TestIterChildEntries(TestCaseWithDirState):
 
1396
 
 
1397
    def create_dirstate_with_two_trees(self):
 
1398
        """This dirstate contains multiple files and directories.
 
1399
 
 
1400
         /        a-root-value
 
1401
         a/       a-dir
 
1402
         b/       b-dir
 
1403
         c        c-file
 
1404
         d        d-file
 
1405
         a/e/     e-dir
 
1406
         a/f      f-file
 
1407
         b/g      g-file
 
1408
         b/h\xc3\xa5  h-\xc3\xa5-file  #This is u'\xe5' encoded into utf-8
 
1409
 
 
1410
        Notice that a/e is an empty directory.
 
1411
 
 
1412
        There is one parent tree, which has the same shape with the following variations:
 
1413
        b/g in the parent is gone.
 
1414
        b/h in the parent has a different id
 
1415
        b/i is new in the parent 
 
1416
        c is renamed to b/j in the parent
 
1417
 
 
1418
        :return: The dirstate, still write-locked.
 
1419
        """
 
1420
        packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
 
1421
        null_sha = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
 
1422
        NULL_PARENT_DETAILS = dirstate.DirState.NULL_PARENT_DETAILS
 
1423
        root_entry = ('', '', 'a-root-value'), [
 
1424
            ('d', '', 0, False, packed_stat),
 
1425
            ('d', '', 0, False, 'parent-revid'),
 
1426
            ]
 
1427
        a_entry = ('', 'a', 'a-dir'), [
 
1428
            ('d', '', 0, False, packed_stat),
 
1429
            ('d', '', 0, False, 'parent-revid'),
 
1430
            ]
 
1431
        b_entry = ('', 'b', 'b-dir'), [
 
1432
            ('d', '', 0, False, packed_stat),
 
1433
            ('d', '', 0, False, 'parent-revid'),
 
1434
            ]
 
1435
        c_entry = ('', 'c', 'c-file'), [
 
1436
            ('f', null_sha, 10, False, packed_stat),
 
1437
            ('r', 'b/j', 0, False, ''),
 
1438
            ]
 
1439
        d_entry = ('', 'd', 'd-file'), [
 
1440
            ('f', null_sha, 20, False, packed_stat),
 
1441
            ('f', 'd', 20, False, 'parent-revid'),
 
1442
            ]
 
1443
        e_entry = ('a', 'e', 'e-dir'), [
 
1444
            ('d', '', 0, False, packed_stat),
 
1445
            ('d', '', 0, False, 'parent-revid'),
 
1446
            ]
 
1447
        f_entry = ('a', 'f', 'f-file'), [
 
1448
            ('f', null_sha, 30, False, packed_stat),
 
1449
            ('f', 'f', 20, False, 'parent-revid'),
 
1450
            ]
 
1451
        g_entry = ('b', 'g', 'g-file'), [
 
1452
            ('f', null_sha, 30, False, packed_stat),
 
1453
            NULL_PARENT_DETAILS,
 
1454
            ]
 
1455
        h_entry1 = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file1'), [
 
1456
            ('f', null_sha, 40, False, packed_stat),
 
1457
            NULL_PARENT_DETAILS,
 
1458
            ]
 
1459
        h_entry2 = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file2'), [
 
1460
            NULL_PARENT_DETAILS,
 
1461
            ('f', 'h', 20, False, 'parent-revid'),
 
1462
            ]
 
1463
        i_entry = ('b', 'i', 'i-file'), [
 
1464
            NULL_PARENT_DETAILS,
 
1465
            ('f', 'h', 20, False, 'parent-revid'),
 
1466
            ]
 
1467
        j_entry = ('b', 'j', 'c-file'), [
 
1468
            ('r', 'c', 0, False, ''),
 
1469
            ('f', 'j', 20, False, 'parent-revid'),
 
1470
            ]
 
1471
        dirblocks = []
 
1472
        dirblocks.append(('', [root_entry]))
 
1473
        dirblocks.append(('', [a_entry, b_entry, c_entry, d_entry]))
 
1474
        dirblocks.append(('a', [e_entry, f_entry]))
 
1475
        dirblocks.append(('b', [g_entry, h_entry1, h_entry2, i_entry, j_entry]))
 
1476
        state = dirstate.DirState.initialize('dirstate')
 
1477
        state._validate()
 
1478
        try:
 
1479
            state._set_data(['parent'], dirblocks)
 
1480
        except:
 
1481
            state.unlock()
 
1482
            raise
 
1483
        return state, dirblocks
 
1484
 
 
1485
    def test_iter_children_b(self):
 
1486
        state, dirblocks = self.create_dirstate_with_two_trees()
 
1487
        self.addCleanup(state.unlock)
 
1488
        expected_result = []
 
1489
        expected_result.append(dirblocks[3][1][2]) # h2
 
1490
        expected_result.append(dirblocks[3][1][3]) # i
 
1491
        expected_result.append(dirblocks[3][1][4]) # j
 
1492
        self.assertEqual(expected_result,
 
1493
            list(state._iter_child_entries(1, 'b')))
 
1494
 
 
1495
    def test_iter_child_root(self):
 
1496
        state, dirblocks = self.create_dirstate_with_two_trees()
 
1497
        self.addCleanup(state.unlock)
 
1498
        expected_result = []
 
1499
        expected_result.append(dirblocks[1][1][0]) # a
 
1500
        expected_result.append(dirblocks[1][1][1]) # b
 
1501
        expected_result.append(dirblocks[1][1][3]) # d
 
1502
        expected_result.append(dirblocks[2][1][0]) # e
 
1503
        expected_result.append(dirblocks[2][1][1]) # f
 
1504
        expected_result.append(dirblocks[3][1][2]) # h2
 
1505
        expected_result.append(dirblocks[3][1][3]) # i
 
1506
        expected_result.append(dirblocks[3][1][4]) # j
 
1507
        self.assertEqual(expected_result,
 
1508
            list(state._iter_child_entries(1, '')))
 
1509
 
 
1510
 
1397
1511
class TestDirstateSortOrder(TestCaseWithTransport):
1398
1512
    """Test that DirState adds entries in the right order."""
1399
1513
 
1598
1712
 
1599
1713
    def test_update_entry_symlink(self):
1600
1714
        """Update entry should read symlinks."""
1601
 
        if not osutils.has_symlinks():
1602
 
            # PlatformDeficiency / TestSkipped
1603
 
            raise TestSkipped("No symlink support")
 
1715
        self.requireFeature(SymlinkFeature)
1604
1716
        state, entry = self.get_state_with_a()
1605
1717
        state.save()
1606
1718
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1757
1869
 
1758
1870
    def test_update_file_to_symlink(self):
1759
1871
        """File becomes a symlink"""
1760
 
        if not osutils.has_symlinks():
1761
 
            # PlatformDeficiency / TestSkipped
1762
 
            raise TestSkipped("No symlink support")
 
1872
        self.requireFeature(SymlinkFeature)
1763
1873
        state, entry = self.get_state_with_a()
1764
1874
        # The file sha1 won't be cached unless the file is old
1765
1875
        state.adjust_time(+10)
1778
1888
 
1779
1889
    def test_update_dir_to_symlink(self):
1780
1890
        """Directory becomes a symlink"""
1781
 
        if not osutils.has_symlinks():
1782
 
            # PlatformDeficiency / TestSkipped
1783
 
            raise TestSkipped("No symlink support")
 
1891
        self.requireFeature(SymlinkFeature)
1784
1892
        state, entry = self.get_state_with_a()
1785
1893
        # The symlink target won't be cached if it isn't old
1786
1894
        state.adjust_time(+10)
1790
1898
 
1791
1899
    def test_update_symlink_to_file(self):
1792
1900
        """Symlink becomes a file"""
1793
 
        if not has_symlinks():
1794
 
            raise TestSkipped("No symlink support")
 
1901
        self.requireFeature(SymlinkFeature)
1795
1902
        state, entry = self.get_state_with_a()
1796
1903
        # The symlink and file info won't be cached unless old
1797
1904
        state.adjust_time(+10)
1801
1908
 
1802
1909
    def test_update_symlink_to_dir(self):
1803
1910
        """Symlink becomes a directory"""
1804
 
        if not has_symlinks():
1805
 
            raise TestSkipped("No symlink support")
 
1911
        self.requireFeature(SymlinkFeature)
1806
1912
        state, entry = self.get_state_with_a()
1807
1913
        # The symlink target won't be cached if it isn't old
1808
1914
        state.adjust_time(+10)