~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__dirstate_helpers.py

  • Committer: Johan Walles
  • Date: 2009-05-06 05:36:28 UTC
  • mfrom: (4332 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4343.
  • Revision ID: johan.walles@gmail.com-20090506053628-tbf1wz4a0m9t684g
MergeĀ fromĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    tests,
28
28
    )
29
29
from bzrlib.tests import (
30
 
        SymlinkFeature,
31
 
        )
32
 
from bzrlib.tests import test_dirstate
 
30
    test_dirstate,
 
31
    test_osutils,
 
32
    )
 
33
 
 
34
try:
 
35
    from bzrlib import _dirstate_helpers_c
 
36
    has_dirstate_helpers_c = True
 
37
except ImportError:
 
38
    has_dirstate_helpers_c = False
33
39
 
34
40
 
35
41
class _CompiledDirstateHelpersFeature(tests.Feature):
36
42
    def _probe(self):
37
 
        try:
38
 
            import bzrlib._dirstate_helpers_c
39
 
        except ImportError:
40
 
            return False
41
 
        return True
 
43
        return has_dirstate_helpers_c
42
44
 
43
45
    def feature_name(self):
44
46
        return 'bzrlib._dirstate_helpers_c'
45
 
 
46
47
CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
47
48
 
48
49
 
 
50
def load_tests(basic_tests, module, loader):
 
51
    # FIXME: we should also parametrize against SHA1Provider !
 
52
    suite = loader.suiteClass()
 
53
    remaining_tests = basic_tests
 
54
 
 
55
    dir_reader_scenarios = test_osutils.dir_reader_scenarios()
 
56
 
 
57
    ue_scenarios = [('dirstate_Python',
 
58
                     {'update_entry': dirstate.py_update_entry})]
 
59
    if has_dirstate_helpers_c:
 
60
        c_scenario = ('dirstate_C',
 
61
                     {'update_entry': _dirstate_helpers_c.update_entry})
 
62
        ue_scenarios.append(c_scenario)
 
63
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
 
64
        remaining_tests, tests.condition_isinstance(TestUpdateEntry))
 
65
    tests.multiply_tests(process_entry_tests,
 
66
                         tests.multiply_scenarios(dir_reader_scenarios,
 
67
                                                  ue_scenarios),
 
68
                         suite)
 
69
 
 
70
    pe_scenarios = [('dirstate_Python',
 
71
                     {'_process_entry': dirstate.ProcessEntryPython})]
 
72
    if has_dirstate_helpers_c:
 
73
        c_scenario = ('dirstate_C',
 
74
                     {'_process_entry': _dirstate_helpers_c.ProcessEntryC})
 
75
        pe_scenarios.append(c_scenario)
 
76
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
 
77
        remaining_tests, tests.condition_isinstance(TestProcessEntry))
 
78
    tests.multiply_tests(process_entry_tests,
 
79
                         tests.multiply_scenarios(dir_reader_scenarios,
 
80
                                                  pe_scenarios),
 
81
                         suite)
 
82
 
 
83
    dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
 
84
        remaining_tests, tests.condition_isinstance(
 
85
            test_dirstate.TestCaseWithDirState))
 
86
    tests.multiply_tests(dir_reader_tests, dir_reader_scenarios, suite)
 
87
    suite.addTest(remaining_tests)
 
88
 
 
89
    return suite
 
90
 
 
91
 
49
92
class TestBisectPathMixin(object):
50
93
    """Test that _bisect_path_*() returns the expected values.
51
94
 
790
833
class TestUpdateEntry(test_dirstate.TestCaseWithDirState):
791
834
    """Test the DirState.update_entry functions"""
792
835
 
 
836
    # Set by load_tests
 
837
    update_entry = None
 
838
 
 
839
    def setUp(self):
 
840
        super(TestUpdateEntry, self).setUp()
 
841
        orig = dirstate.update_entry
 
842
        def cleanup():
 
843
            dirstate.update_entry = orig
 
844
        self.addCleanup(cleanup)
 
845
        dirstate.update_entry = self.update_entry
 
846
 
793
847
    def get_state_with_a(self):
794
848
        """Create a DirState tracking a single object named 'a'"""
795
849
        state = test_dirstate.InstrumentedDirState.initialize('dirstate')
796
850
        self.addCleanup(state.unlock)
797
851
        state.add('a', 'a-id', 'file', None, '')
798
852
        entry = state._get_entry(0, path_utf8='a')
799
 
        self.set_update_entry()
800
853
        return state, entry
801
854
 
802
 
    def set_update_entry(self):
803
 
        self.update_entry = dirstate.py_update_entry
804
 
 
805
855
    def test_observed_sha1_cachable(self):
806
856
        state, entry = self.get_state_with_a()
807
857
        atime = time.time() - 10
921
971
 
922
972
    def test_update_entry_symlink(self):
923
973
        """Update entry should read symlinks."""
924
 
        self.requireFeature(SymlinkFeature)
 
974
        self.requireFeature(tests.SymlinkFeature)
925
975
        state, entry = self.get_state_with_a()
926
976
        state.save()
927
977
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1022
1072
                         state._dirblock_state)
1023
1073
 
1024
1074
    def test_update_entry_tree_reference(self):
1025
 
        self.set_update_entry()
1026
1075
        state = test_dirstate.InstrumentedDirState.initialize('dirstate')
1027
1076
        self.addCleanup(state.unlock)
1028
1077
        state.add('r', 'r-id', 'tree-reference', None, '')
1064
1113
 
1065
1114
        return packed_stat
1066
1115
 
 
1116
    # FIXME: Add unicode version
1067
1117
    def create_and_test_symlink(self, state, entry):
1068
1118
        """Create a symlink at 'a' and verify the state finds it.
1069
1119
 
1098
1148
 
1099
1149
    def test_update_file_to_symlink(self):
1100
1150
        """File becomes a symlink"""
1101
 
        self.requireFeature(SymlinkFeature)
 
1151
        self.requireFeature(tests.SymlinkFeature)
1102
1152
        state, entry = self.get_state_with_a()
1103
1153
        # The file sha1 won't be cached unless the file is old
1104
1154
        state.adjust_time(+10)
1117
1167
 
1118
1168
    def test_update_dir_to_symlink(self):
1119
1169
        """Directory becomes a symlink"""
1120
 
        self.requireFeature(SymlinkFeature)
 
1170
        self.requireFeature(tests.SymlinkFeature)
1121
1171
        state, entry = self.get_state_with_a()
1122
1172
        # The symlink target won't be cached if it isn't old
1123
1173
        state.adjust_time(+10)
1127
1177
 
1128
1178
    def test_update_symlink_to_file(self):
1129
1179
        """Symlink becomes a file"""
1130
 
        self.requireFeature(SymlinkFeature)
 
1180
        self.requireFeature(tests.SymlinkFeature)
1131
1181
        state, entry = self.get_state_with_a()
1132
1182
        # The symlink and file info won't be cached unless old
1133
1183
        state.adjust_time(+10)
1137
1187
 
1138
1188
    def test_update_symlink_to_dir(self):
1139
1189
        """Symlink becomes a directory"""
1140
 
        self.requireFeature(SymlinkFeature)
 
1190
        self.requireFeature(tests.SymlinkFeature)
1141
1191
        state, entry = self.get_state_with_a()
1142
1192
        # The symlink target won't be cached if it isn't old
1143
1193
        state.adjust_time(+10)
1166
1216
        self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
1167
1217
                         entry[1])
1168
1218
 
1169
 
        # Make the disk object look old enough to cache (but it won't cache the sha
1170
 
        # as it is a new file).
 
1219
        # Make the disk object look old enough to cache (but it won't cache the
 
1220
        # sha as it is a new file).
1171
1221
        state.adjust_time(+20)
1172
1222
        digest = 'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6'
1173
1223
        self.update_entry(state, entry, abspath='a', stat_value=stat_value)
1194
1244
        entry = state._get_entry(0, path_utf8='a file')
1195
1245
        state._sha_cutoff_time()
1196
1246
        state._cutoff_time += 10
1197
 
        sha1 = dirstate.update_entry(state, entry, 'tree/a file',
1198
 
            os.lstat('tree/a file'))
 
1247
        sha1 = self.update_entry(state, entry, 'tree/a file',
 
1248
                                 os.lstat('tree/a file'))
1199
1249
        self.assertEqual(expected_sha, sha1)
1200
1250
 
1201
1251
    def test_sha1provider_stat_and_sha1_used(self):
1206
1256
        state._sha1_provider = UppercaseSHA1Provider()
1207
1257
        # If we used the standard provider, it would look like nothing has
1208
1258
        # changed
1209
 
        file_ids_changed = [change[0] for change 
1210
 
                in tree.iter_changes(tree.basis_tree())]
 
1259
        file_ids_changed = [change[0] for change
 
1260
                            in tree.iter_changes(tree.basis_tree())]
1211
1261
        self.assertEqual(['a-file-id'], file_ids_changed)
1212
1262
 
1213
1263
 
1228
1278
        return statvalue, sha1
1229
1279
 
1230
1280
 
1231
 
class TestCompiledUpdateEntry(TestUpdateEntry):
1232
 
    """Test the pyrex implementation of _read_dirblocks"""
1233
 
 
1234
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
1235
 
 
1236
 
    def set_update_entry(self):
1237
 
        from bzrlib._dirstate_helpers_c import update_entry
1238
 
        self.update_entry = update_entry
1239
 
 
1240
 
 
1241
 
class TestProcessEntryPython(test_dirstate.TestCaseWithDirState):
 
1281
class TestProcessEntry(test_dirstate.TestCaseWithDirState):
 
1282
 
 
1283
    # Set by load_tests
 
1284
    _process_entry = None
1242
1285
 
1243
1286
    def setUp(self):
1244
 
        super(TestProcessEntryPython, self).setUp()
1245
 
        self.setup_process_entry()
1246
 
 
1247
 
    def setup_process_entry(self):
1248
 
        from bzrlib import dirstate
 
1287
        super(TestProcessEntry, self).setUp()
1249
1288
        orig = dirstate._process_entry
1250
1289
        def cleanup():
1251
1290
            dirstate._process_entry = orig
1252
1291
        self.addCleanup(cleanup)
1253
 
        dirstate._process_entry = dirstate.ProcessEntryPython
 
1292
        dirstate._process_entry = self._process_entry
1254
1293
 
1255
1294
    def assertChangedFileIds(self, expected, tree):
1256
1295
        tree.lock_read()
1280
1319
        state._sha1_provider = UppercaseSHA1Provider()
1281
1320
        self.assertChangedFileIds(['file-id'], tree)
1282
1321
 
1283
 
 
1284
 
class TestProcessEntryC(TestProcessEntryPython):
1285
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
1286
 
 
1287
 
    def setup_process_entry(self):
1288
 
        from bzrlib import _dirstate_helpers_c
1289
 
        orig = dirstate._process_entry
1290
 
        def cleanup():
1291
 
            dirstate._process_entry = orig
1292
 
        self.addCleanup(cleanup)
1293
 
        dirstate._process_entry = _dirstate_helpers_c.ProcessEntryC
1294