35
from bzrlib import _dirstate_helpers_c
36
has_dirstate_helpers_c = True
38
has_dirstate_helpers_c = False
41
class _CompiledDirstateHelpersFeature(tests.Feature):
43
return has_dirstate_helpers_c
45
def feature_name(self):
46
return 'bzrlib._dirstate_helpers_c'
47
CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
35
50
def load_tests(basic_tests, module, loader):
36
# FIXME: we should also parametrize agsinst C/Python
51
# FIXME: we should also parametrize agsinst Sha1Providers !
37
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,
38
83
dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
39
basic_tests, tests.condition_isinstance(
84
remaining_tests, tests.condition_isinstance(
40
85
test_dirstate.TestCaseWithDirState))
41
tests.multiply_tests(dir_reader_tests,
42
test_osutils.dir_reader_scenarios(), suite)
86
tests.multiply_tests(dir_reader_tests, dir_reader_scenarios, suite)
43
87
suite.addTest(remaining_tests)
47
class _CompiledDirstateHelpersFeature(tests.Feature):
50
import bzrlib._dirstate_helpers_c
55
def feature_name(self):
56
return 'bzrlib._dirstate_helpers_c'
58
CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
61
92
class TestBisectPathMixin(object):
62
93
"""Test that _bisect_path_*() returns the expected values.
802
833
class TestUpdateEntry(test_dirstate.TestCaseWithDirState):
803
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
805
847
def get_state_with_a(self):
806
848
"""Create a DirState tracking a single object named 'a'"""
807
849
state = test_dirstate.InstrumentedDirState.initialize('dirstate')
808
850
self.addCleanup(state.unlock)
809
851
state.add('a', 'a-id', 'file', None, '')
810
852
entry = state._get_entry(0, path_utf8='a')
811
self.set_update_entry()
812
853
return state, entry
814
def set_update_entry(self):
815
self.update_entry = dirstate.py_update_entry
817
855
def test_observed_sha1_cachable(self):
818
856
state, entry = self.get_state_with_a()
819
857
atime = time.time() - 10
1178
1216
self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
1181
# Make the disk object look old enough to cache (but it won't cache the sha
1182
# 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).
1183
1221
state.adjust_time(+20)
1184
1222
digest = 'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6'
1185
1223
self.update_entry(state, entry, abspath='a', stat_value=stat_value)
1206
1244
entry = state._get_entry(0, path_utf8='a file')
1207
1245
state._sha_cutoff_time()
1208
1246
state._cutoff_time += 10
1209
sha1 = dirstate.update_entry(state, entry, 'tree/a file',
1210
os.lstat('tree/a file'))
1247
sha1 = self.update_entry(state, entry, 'tree/a file',
1248
os.lstat('tree/a file'))
1211
1249
self.assertEqual(expected_sha, sha1)
1213
1251
def test_sha1provider_stat_and_sha1_used(self):
1218
1256
state._sha1_provider = UppercaseSHA1Provider()
1219
1257
# If we used the standard provider, it would look like nothing has
1221
file_ids_changed = [change[0] for change
1222
in tree.iter_changes(tree.basis_tree())]
1259
file_ids_changed = [change[0] for change
1260
in tree.iter_changes(tree.basis_tree())]
1223
1261
self.assertEqual(['a-file-id'], file_ids_changed)
1240
1278
return statvalue, sha1
1243
class TestCompiledUpdateEntry(TestUpdateEntry):
1244
"""Test the pyrex implementation of _read_dirblocks"""
1246
_test_needs_features = [CompiledDirstateHelpersFeature]
1248
def set_update_entry(self):
1249
from bzrlib._dirstate_helpers_c import update_entry
1250
self.update_entry = update_entry
1253
class TestProcessEntryPython(test_dirstate.TestCaseWithDirState):
1281
class TestProcessEntry(test_dirstate.TestCaseWithDirState):
1284
_process_entry = None
1255
1286
def setUp(self):
1256
super(TestProcessEntryPython, self).setUp()
1257
self.setup_process_entry()
1259
def setup_process_entry(self):
1260
from bzrlib import dirstate
1287
super(TestProcessEntry, self).setUp()
1261
1288
orig = dirstate._process_entry
1263
1290
dirstate._process_entry = orig
1264
1291
self.addCleanup(cleanup)
1265
dirstate._process_entry = dirstate.ProcessEntryPython
1292
dirstate._process_entry = self._process_entry
1267
1294
def assertChangedFileIds(self, expected, tree):
1268
1295
tree.lock_read()
1292
1319
state._sha1_provider = UppercaseSHA1Provider()
1293
1320
self.assertChangedFileIds(['file-id'], tree)
1296
class TestProcessEntryC(TestProcessEntryPython):
1297
_test_needs_features = [CompiledDirstateHelpersFeature]
1299
def setup_process_entry(self):
1300
from bzrlib import _dirstate_helpers_c
1301
orig = dirstate._process_entry
1303
dirstate._process_entry = orig
1304
self.addCleanup(cleanup)
1305
dirstate._process_entry = _dirstate_helpers_c.ProcessEntryC