29
29
from bzrlib.tests import (
32
from bzrlib.tests import test_dirstate
35
from bzrlib import _dirstate_helpers_c
36
has_dirstate_helpers_c = True
38
has_dirstate_helpers_c = False
35
41
class _CompiledDirstateHelpersFeature(tests.Feature):
38
import bzrlib._dirstate_helpers_c
43
return has_dirstate_helpers_c
43
45
def feature_name(self):
44
46
return 'bzrlib._dirstate_helpers_c'
46
47
CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
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
55
dir_reader_scenarios = test_osutils.dir_reader_scenarios()
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,
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,
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)
49
92
class TestBisectPathMixin(object):
50
93
"""Test that _bisect_path_*() returns the expected values.
790
833
class TestUpdateEntry(test_dirstate.TestCaseWithDirState):
791
834
"""Test the DirState.update_entry functions"""
840
super(TestUpdateEntry, self).setUp()
841
orig = dirstate.update_entry
843
dirstate.update_entry = orig
844
self.addCleanup(cleanup)
845
dirstate.update_entry = self.update_entry
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
802
def set_update_entry(self):
803
self.update_entry = dirstate.py_update_entry
805
855
def test_observed_sha1_cachable(self):
806
856
state, entry = self.get_state_with_a()
807
857
atime = time.time() - 10
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()
927
977
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1166
1216
self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
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)
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
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)
1228
1278
return statvalue, sha1
1231
class TestCompiledUpdateEntry(TestUpdateEntry):
1232
"""Test the pyrex implementation of _read_dirblocks"""
1234
_test_needs_features = [CompiledDirstateHelpersFeature]
1236
def set_update_entry(self):
1237
from bzrlib._dirstate_helpers_c import update_entry
1238
self.update_entry = update_entry
1241
class TestProcessEntryPython(test_dirstate.TestCaseWithDirState):
1281
class TestProcessEntry(test_dirstate.TestCaseWithDirState):
1284
_process_entry = None
1243
1286
def setUp(self):
1244
super(TestProcessEntryPython, self).setUp()
1245
self.setup_process_entry()
1247
def setup_process_entry(self):
1248
from bzrlib import dirstate
1287
super(TestProcessEntry, self).setUp()
1249
1288
orig = dirstate._process_entry
1251
1290
dirstate._process_entry = orig
1252
1291
self.addCleanup(cleanup)
1253
dirstate._process_entry = dirstate.ProcessEntryPython
1292
dirstate._process_entry = self._process_entry
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)
1284
class TestProcessEntryC(TestProcessEntryPython):
1285
_test_needs_features = [CompiledDirstateHelpersFeature]
1287
def setup_process_entry(self):
1288
from bzrlib import _dirstate_helpers_c
1289
orig = dirstate._process_entry
1291
dirstate._process_entry = orig
1292
self.addCleanup(cleanup)
1293
dirstate._process_entry = _dirstate_helpers_c.ProcessEntryC