38
38
has_dirstate_helpers_pyx = False
41
compiled_dirstate_helpers_feature = tests.ModuleAvailableFeature(
42
'bzrlib._dirstate_helpers_pyx')
41
class _CompiledDirstateHelpersFeature(tests.Feature):
43
return has_dirstate_helpers_pyx
45
def feature_name(self):
46
return 'bzrlib._dirstate_helpers_pyx'
47
CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
45
50
def load_tests(basic_tests, module, loader):
52
57
ue_scenarios = [('dirstate_Python',
53
58
{'update_entry': dirstate.py_update_entry})]
54
if compiled_dirstate_helpers_feature.available():
55
update_entry = compiled_dirstate_helpers_feature.module.update_entry
56
pyrex_scenario = ('dirstate_Pyrex', {'update_entry': update_entry})
59
if has_dirstate_helpers_pyx:
60
pyrex_scenario = ('dirstate_Pyrex',
61
{'update_entry': _dirstate_helpers_pyx.update_entry})
57
62
ue_scenarios.append(pyrex_scenario)
58
63
process_entry_tests, remaining_tests = tests.split_suite_by_condition(
59
64
remaining_tests, tests.condition_isinstance(TestUpdateEntry))
65
70
pe_scenarios = [('dirstate_Python',
66
71
{'_process_entry': dirstate.ProcessEntryPython})]
67
if compiled_dirstate_helpers_feature.available():
68
process_entry = compiled_dirstate_helpers_feature.module.ProcessEntryC
69
pyrex_scenario = ('dirstate_Pyrex', {'_process_entry': process_entry})
72
if has_dirstate_helpers_pyx:
75
{'_process_entry': _dirstate_helpers_pyx.ProcessEntryC})
70
76
pe_scenarios.append(pyrex_scenario)
71
77
process_entry_tests, remaining_tests = tests.split_suite_by_condition(
72
78
remaining_tests, tests.condition_isinstance(TestProcessEntry))
253
259
class TestCompiledBisectPathLeft(TestBisectPathLeft):
254
260
"""Run all Bisect Path tests against _bisect_path_lect"""
256
_test_needs_features = [compiled_dirstate_helpers_feature]
262
_test_needs_features = [CompiledDirstateHelpersFeature]
258
264
def get_bisect_path(self):
259
265
from bzrlib._dirstate_helpers_pyx import _bisect_path_left
274
280
class TestCompiledBisectPathRight(TestBisectPathRight):
275
281
"""Run all Bisect Path tests against _bisect_path_right"""
277
_test_needs_features = [compiled_dirstate_helpers_feature]
283
_test_needs_features = [CompiledDirstateHelpersFeature]
279
285
def get_bisect_path(self):
280
286
from bzrlib._dirstate_helpers_pyx import _bisect_path_right
508
514
class TestCompiledCmpByDirs(TestCmpByDirs):
509
515
"""Test the pyrex implementation of cmp_by_dirs"""
511
_test_needs_features = [compiled_dirstate_helpers_feature]
517
_test_needs_features = [CompiledDirstateHelpersFeature]
513
519
def get_cmp_by_dirs(self):
514
520
from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
659
665
class TestCompiledCmpPathByDirblock(TestCmpPathByDirblock):
660
666
"""Test the pyrex implementation of _cmp_path_by_dirblock"""
662
_test_needs_features = [compiled_dirstate_helpers_feature]
668
_test_needs_features = [CompiledDirstateHelpersFeature]
664
670
def get_cmp_by_dirs(self):
665
671
from bzrlib._dirstate_helpers_pyx import _cmp_path_by_dirblock
669
675
class TestMemRChr(tests.TestCase):
670
676
"""Test memrchr functionality"""
672
_test_needs_features = [compiled_dirstate_helpers_feature]
678
_test_needs_features = [CompiledDirstateHelpersFeature]
674
680
def assertMemRChr(self, expected, s, c):
675
681
from bzrlib._dirstate_helpers_pyx import _py_memrchr
757
763
class TestCompiledReadDirblocks(TestReadDirblocks):
758
764
"""Test the pyrex implementation of _read_dirblocks"""
760
_test_needs_features = [compiled_dirstate_helpers_feature]
766
_test_needs_features = [CompiledDirstateHelpersFeature]
762
768
def get_read_dirblocks(self):
763
769
from bzrlib._dirstate_helpers_pyx import _read_dirblocks
775
781
def test_bisect_dirblock(self):
776
if compiled_dirstate_helpers_feature.available():
782
if CompiledDirstateHelpersFeature.available():
777
783
from bzrlib._dirstate_helpers_pyx import bisect_dirblock
779
785
from bzrlib._dirstate_helpers_py import bisect_dirblock
780
786
self.assertIs(bisect_dirblock, dirstate.bisect_dirblock)
782
788
def test__bisect_path_left(self):
783
if compiled_dirstate_helpers_feature.available():
789
if CompiledDirstateHelpersFeature.available():
784
790
from bzrlib._dirstate_helpers_pyx import _bisect_path_left
786
792
from bzrlib._dirstate_helpers_py import _bisect_path_left
787
793
self.assertIs(_bisect_path_left, dirstate._bisect_path_left)
789
795
def test__bisect_path_right(self):
790
if compiled_dirstate_helpers_feature.available():
796
if CompiledDirstateHelpersFeature.available():
791
797
from bzrlib._dirstate_helpers_pyx import _bisect_path_right
793
799
from bzrlib._dirstate_helpers_py import _bisect_path_right
794
800
self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
796
802
def test_cmp_by_dirs(self):
797
if compiled_dirstate_helpers_feature.available():
803
if CompiledDirstateHelpersFeature.available():
798
804
from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
800
806
from bzrlib._dirstate_helpers_py import cmp_by_dirs
801
807
self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)
803
809
def test__read_dirblocks(self):
804
if compiled_dirstate_helpers_feature.available():
810
if CompiledDirstateHelpersFeature.available():
805
811
from bzrlib._dirstate_helpers_pyx import _read_dirblocks
807
813
from bzrlib._dirstate_helpers_py import _read_dirblocks
808
814
self.assertIs(_read_dirblocks, dirstate._read_dirblocks)
810
816
def test_update_entry(self):
811
if compiled_dirstate_helpers_feature.available():
817
if CompiledDirstateHelpersFeature.available():
812
818
from bzrlib._dirstate_helpers_pyx import update_entry
814
820
from bzrlib.dirstate import update_entry
815
821
self.assertIs(update_entry, dirstate.update_entry)
817
823
def test_process_entry(self):
818
if compiled_dirstate_helpers_feature.available():
824
if CompiledDirstateHelpersFeature.available():
819
825
from bzrlib._dirstate_helpers_pyx import ProcessEntryC
820
826
self.assertIs(ProcessEntryC, dirstate._process_entry)
833
839
super(TestUpdateEntry, self).setUp()
834
self.overrideAttr(dirstate, 'update_entry', self.update_entry)
840
orig = dirstate.update_entry
842
dirstate.update_entry = orig
843
self.addCleanup(cleanup)
844
dirstate.update_entry = self.update_entry
836
846
def get_state_with_a(self):
837
847
"""Create a DirState tracking a single object named 'a'"""
1275
1285
def setUp(self):
1276
1286
super(TestProcessEntry, self).setUp()
1277
self.overrideAttr(dirstate, '_process_entry', self._process_entry)
1287
orig = dirstate._process_entry
1289
dirstate._process_entry = orig
1290
self.addCleanup(cleanup)
1291
dirstate._process_entry = self._process_entry
1279
1293
def assertChangedFileIds(self, expected, tree):
1280
1294
tree.lock_read()
1286
1300
self.assertEqual(sorted(expected), sorted(file_ids))
1288
def test_exceptions_raised(self):
1289
# This is a direct test of bug #495023, it relies on osutils.is_inside
1290
# getting called in an inner function. Which makes it a bit brittle,
1291
# but at least it does reproduce the bug.
1292
tree = self.make_branch_and_tree('tree')
1293
self.build_tree(['tree/file', 'tree/dir/', 'tree/dir/sub',
1294
'tree/dir2/', 'tree/dir2/sub2'])
1295
tree.add(['file', 'dir', 'dir/sub', 'dir2', 'dir2/sub2'])
1296
tree.commit('first commit')
1298
self.addCleanup(tree.unlock)
1299
basis_tree = tree.basis_tree()
1300
def is_inside_raises(*args, **kwargs):
1301
raise RuntimeError('stop this')
1302
self.overrideAttr(osutils, 'is_inside', is_inside_raises)
1303
self.assertListRaises(RuntimeError, tree.iter_changes, basis_tree)
1305
1302
def test_simple_changes(self):
1306
1303
tree = self.make_branch_and_tree('tree')
1307
1304
self.build_tree(['tree/file'])