~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-17 15:33:07 UTC
  • mfrom: (4297.2.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090417153307-fmbzf4klhhqbawrh
(vila) (trivial) More cleanup test imports and use features to better
        track skipped tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    dirstate,
24
24
    errors,
25
25
    inventory,
 
26
    memorytree,
26
27
    osutils,
27
28
    revision as _mod_revision,
 
29
    tests,
28
30
    )
29
 
from bzrlib.memorytree import MemoryTree
30
 
from bzrlib.tests import (
31
 
        SymlinkFeature,
32
 
        TestCase,
33
 
        TestCaseInTempDir,
34
 
        TestCaseWithTransport,
35
 
        )
 
31
from bzrlib.tests import test_osutils
36
32
 
37
33
 
38
34
# TODO:
48
44
# set_path_id  setting id when state is in memory modified
49
45
 
50
46
 
51
 
class TestCaseWithDirState(TestCaseWithTransport):
 
47
class TestCaseWithDirState(tests.TestCaseWithTransport):
52
48
    """Helper functions for creating DirState objects with various content."""
53
49
 
54
50
    def create_empty_dirstate(self):
931
927
        finally:
932
928
            tree1.unlock()
933
929
        branch2 = tree1.branch.bzrdir.clone('tree2').open_branch()
934
 
        tree2 = MemoryTree.create_on_branch(branch2)
 
930
        tree2 = memorytree.MemoryTree.create_on_branch(branch2)
935
931
        tree2.lock_write()
936
932
        try:
937
933
            revid2 = tree2.commit('foo')
1001
997
        finally:
1002
998
            tree1.unlock()
1003
999
        branch2 = tree1.branch.bzrdir.clone('tree2').open_branch()
1004
 
        tree2 = MemoryTree.create_on_branch(branch2)
 
1000
        tree2 = memorytree.MemoryTree.create_on_branch(branch2)
1005
1001
        tree2.lock_write()
1006
1002
        try:
1007
1003
            tree2.put_file_bytes_non_atomic('file-id', 'new file-content')
1066
1062
            state.unlock()
1067
1063
        state = dirstate.DirState.on_file('dirstate')
1068
1064
        state.lock_read()
1069
 
        try:
1070
 
            self.assertEqual(expected_entries, list(state._iter_entries()))
1071
 
        finally:
1072
 
            state.unlock()
 
1065
        self.addCleanup(state.unlock)
 
1066
        self.assertEqual(expected_entries, list(state._iter_entries()))
1073
1067
 
1074
1068
    def test_add_path_to_unversioned_directory(self):
1075
1069
        """Adding a path to an unversioned directory should error.
1080
1074
        """
1081
1075
        self.build_tree(['unversioned/', 'unversioned/a file'])
1082
1076
        state = dirstate.DirState.initialize('dirstate')
1083
 
        try:
1084
 
            self.assertRaises(errors.NotVersionedError, state.add,
1085
 
                'unversioned/a file', 'a-file-id', 'file', None, None)
1086
 
        finally:
1087
 
            state.unlock()
 
1077
        self.addCleanup(state.unlock)
 
1078
        self.assertRaises(errors.NotVersionedError, state.add,
 
1079
                          'unversioned/a file', 'a-file-id', 'file', None, None)
1088
1080
 
1089
1081
    def test_add_directory_to_root_no_parents_all_data(self):
1090
1082
        # The most trivial addition of a dir is when there are no parents and
1110
1102
            state.unlock()
1111
1103
        state = dirstate.DirState.on_file('dirstate')
1112
1104
        state.lock_read()
 
1105
        self.addCleanup(state.unlock)
1113
1106
        state._validate()
1114
 
        try:
1115
 
            self.assertEqual(expected_entries, list(state._iter_entries()))
1116
 
        finally:
1117
 
            state.unlock()
 
1107
        self.assertEqual(expected_entries, list(state._iter_entries()))
1118
1108
 
1119
1109
    def test_add_symlink_to_root_no_parents_all_data(self):
1120
1110
        # The most trivial addition of a symlink when there are no parents and
1121
1111
        # its in the root and all data about the file is supplied
1122
1112
        # bzr doesn't support fake symlinks on windows, yet.
1123
 
        self.requireFeature(SymlinkFeature)
 
1113
        self.requireFeature(tests.SymlinkFeature)
1124
1114
        os.symlink('target', 'a link')
1125
1115
        stat = os.lstat('a link')
1126
1116
        expected_entries = [
1142
1132
            state.unlock()
1143
1133
        state = dirstate.DirState.on_file('dirstate')
1144
1134
        state.lock_read()
1145
 
        try:
1146
 
            self.assertEqual(expected_entries, list(state._iter_entries()))
1147
 
        finally:
1148
 
            state.unlock()
 
1135
        self.addCleanup(state.unlock)
 
1136
        self.assertEqual(expected_entries, list(state._iter_entries()))
1149
1137
 
1150
1138
    def test_add_directory_and_child_no_parents_all_data(self):
1151
1139
        # after adding a directory, we should be able to add children to it.
1176
1164
            state.unlock()
1177
1165
        state = dirstate.DirState.on_file('dirstate')
1178
1166
        state.lock_read()
1179
 
        try:
1180
 
            self.assertEqual(expected_entries, list(state._iter_entries()))
1181
 
        finally:
1182
 
            state.unlock()
 
1167
        self.addCleanup(state.unlock)
 
1168
        self.assertEqual(expected_entries, list(state._iter_entries()))
1183
1169
 
1184
1170
    def test_add_tree_reference(self):
1185
1171
        # make a dirstate and add a tree reference
1199
1185
            state.unlock()
1200
1186
        # now check we can read it back
1201
1187
        state.lock_read()
 
1188
        self.addCleanup(state.unlock)
1202
1189
        state._validate()
1203
 
        try:
1204
 
            entry2 = state._get_entry(0, 'subdir-id', 'subdir')
1205
 
            self.assertEqual(entry, entry2)
1206
 
            self.assertEqual(entry, expected_entry)
1207
 
            # and lookup by id should work too
1208
 
            entry2 = state._get_entry(0, fileid_utf8='subdir-id')
1209
 
            self.assertEqual(entry, expected_entry)
1210
 
        finally:
1211
 
            state.unlock()
 
1190
        entry2 = state._get_entry(0, 'subdir-id', 'subdir')
 
1191
        self.assertEqual(entry, entry2)
 
1192
        self.assertEqual(entry, expected_entry)
 
1193
        # and lookup by id should work too
 
1194
        entry2 = state._get_entry(0, fileid_utf8='subdir-id')
 
1195
        self.assertEqual(entry, expected_entry)
1212
1196
 
1213
1197
    def test_add_forbidden_names(self):
1214
1198
        state = dirstate.DirState.initialize('dirstate')
1552
1536
            list(state._iter_child_entries(1, '')))
1553
1537
 
1554
1538
 
1555
 
class TestDirstateSortOrder(TestCaseWithTransport):
 
1539
class TestDirstateSortOrder(tests.TestCaseWithTransport):
1556
1540
    """Test that DirState adds entries in the right order."""
1557
1541
 
1558
1542
    def test_add_sorting(self):
1674
1658
            st.st_ino, st.st_mode)
1675
1659
 
1676
1660
 
1677
 
class TestPackStat(TestCaseWithTransport):
 
1661
class TestPackStat(tests.TestCaseWithTransport):
1678
1662
 
1679
1663
    def assertPackStat(self, expected, stat_value):
1680
1664
        """Check the packed and serialized form of a stat value."""
2207
2191
        self.assertEqual(exp_dirblocks, state._dirblocks)
2208
2192
 
2209
2193
 
2210
 
class Test_InvEntryToDetails(TestCaseWithDirState):
 
2194
class Test_InvEntryToDetails(tests.TestCase):
2211
2195
 
2212
2196
    def assertDetails(self, expected, inv_entry):
2213
2197
        details = dirstate.DirState._inv_entry_to_details(inv_entry)
2230
2214
                                      'link-revision-id'), inv_entry)
2231
2215
 
2232
2216
 
2233
 
class TestSHA1Provider(TestCaseInTempDir):
 
2217
class TestSHA1Provider(tests.TestCaseInTempDir):
2234
2218
 
2235
2219
    def test_sha1provider_is_an_interface(self):
2236
2220
        p = dirstate.SHA1Provider()