38
38
has_dirstate_helpers_pyx = False
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()
41
compiled_dirstate_helpers_feature = tests.ModuleAvailableFeature(
42
'bzrlib._dirstate_helpers_pyx')
50
45
def load_tests(basic_tests, module, loader):
57
52
ue_scenarios = [('dirstate_Python',
58
53
{'update_entry': dirstate.py_update_entry})]
59
if has_dirstate_helpers_pyx:
60
pyrex_scenario = ('dirstate_Pyrex',
61
{'update_entry': _dirstate_helpers_pyx.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})
62
57
ue_scenarios.append(pyrex_scenario)
63
58
process_entry_tests, remaining_tests = tests.split_suite_by_condition(
64
59
remaining_tests, tests.condition_isinstance(TestUpdateEntry))
70
65
pe_scenarios = [('dirstate_Python',
71
66
{'_process_entry': dirstate.ProcessEntryPython})]
72
if has_dirstate_helpers_pyx:
75
{'_process_entry': _dirstate_helpers_pyx.ProcessEntryC})
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})
76
70
pe_scenarios.append(pyrex_scenario)
77
71
process_entry_tests, remaining_tests = tests.split_suite_by_condition(
78
72
remaining_tests, tests.condition_isinstance(TestProcessEntry))
259
253
class TestCompiledBisectPathLeft(TestBisectPathLeft):
260
254
"""Run all Bisect Path tests against _bisect_path_lect"""
262
_test_needs_features = [CompiledDirstateHelpersFeature]
256
_test_needs_features = [compiled_dirstate_helpers_feature]
264
258
def get_bisect_path(self):
265
259
from bzrlib._dirstate_helpers_pyx import _bisect_path_left
280
274
class TestCompiledBisectPathRight(TestBisectPathRight):
281
275
"""Run all Bisect Path tests against _bisect_path_right"""
283
_test_needs_features = [CompiledDirstateHelpersFeature]
277
_test_needs_features = [compiled_dirstate_helpers_feature]
285
279
def get_bisect_path(self):
286
280
from bzrlib._dirstate_helpers_pyx import _bisect_path_right
514
508
class TestCompiledCmpByDirs(TestCmpByDirs):
515
509
"""Test the pyrex implementation of cmp_by_dirs"""
517
_test_needs_features = [CompiledDirstateHelpersFeature]
511
_test_needs_features = [compiled_dirstate_helpers_feature]
519
513
def get_cmp_by_dirs(self):
520
514
from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
665
659
class TestCompiledCmpPathByDirblock(TestCmpPathByDirblock):
666
660
"""Test the pyrex implementation of _cmp_path_by_dirblock"""
668
_test_needs_features = [CompiledDirstateHelpersFeature]
662
_test_needs_features = [compiled_dirstate_helpers_feature]
670
664
def get_cmp_by_dirs(self):
671
665
from bzrlib._dirstate_helpers_pyx import _cmp_path_by_dirblock
675
669
class TestMemRChr(tests.TestCase):
676
670
"""Test memrchr functionality"""
678
_test_needs_features = [CompiledDirstateHelpersFeature]
672
_test_needs_features = [compiled_dirstate_helpers_feature]
680
674
def assertMemRChr(self, expected, s, c):
681
675
from bzrlib._dirstate_helpers_pyx import _py_memrchr
744
738
def test_trailing_garbage(self):
745
739
tree, state, expected = self.create_basic_dirstate()
746
# We can modify the file as long as it hasn't been read yet.
740
# On Linux, we can write extra data as long as we haven't read yet, but
741
# on Win32, if you've opened the file with FILE_SHARE_READ, trying to
742
# open it in append mode will fail.
747
744
f = open('dirstate', 'ab')
749
746
# Add bogus trailing garbage
750
747
f.write('bogus\n')
753
751
e = self.assertRaises(errors.DirstateCorrupt,
754
752
state._read_dirblocks_if_needed)
755
753
# Make sure we mention the bogus characters in the error
759
757
class TestCompiledReadDirblocks(TestReadDirblocks):
760
758
"""Test the pyrex implementation of _read_dirblocks"""
762
_test_needs_features = [CompiledDirstateHelpersFeature]
760
_test_needs_features = [compiled_dirstate_helpers_feature]
764
762
def get_read_dirblocks(self):
765
763
from bzrlib._dirstate_helpers_pyx import _read_dirblocks
777
775
def test_bisect_dirblock(self):
778
if CompiledDirstateHelpersFeature.available():
776
if compiled_dirstate_helpers_feature.available():
779
777
from bzrlib._dirstate_helpers_pyx import bisect_dirblock
781
779
from bzrlib._dirstate_helpers_py import bisect_dirblock
782
780
self.assertIs(bisect_dirblock, dirstate.bisect_dirblock)
784
782
def test__bisect_path_left(self):
785
if CompiledDirstateHelpersFeature.available():
783
if compiled_dirstate_helpers_feature.available():
786
784
from bzrlib._dirstate_helpers_pyx import _bisect_path_left
788
786
from bzrlib._dirstate_helpers_py import _bisect_path_left
789
787
self.assertIs(_bisect_path_left, dirstate._bisect_path_left)
791
789
def test__bisect_path_right(self):
792
if CompiledDirstateHelpersFeature.available():
790
if compiled_dirstate_helpers_feature.available():
793
791
from bzrlib._dirstate_helpers_pyx import _bisect_path_right
795
793
from bzrlib._dirstate_helpers_py import _bisect_path_right
796
794
self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
798
796
def test_cmp_by_dirs(self):
799
if CompiledDirstateHelpersFeature.available():
797
if compiled_dirstate_helpers_feature.available():
800
798
from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
802
800
from bzrlib._dirstate_helpers_py import cmp_by_dirs
803
801
self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)
805
803
def test__read_dirblocks(self):
806
if CompiledDirstateHelpersFeature.available():
804
if compiled_dirstate_helpers_feature.available():
807
805
from bzrlib._dirstate_helpers_pyx import _read_dirblocks
809
807
from bzrlib._dirstate_helpers_py import _read_dirblocks
810
808
self.assertIs(_read_dirblocks, dirstate._read_dirblocks)
812
810
def test_update_entry(self):
813
if CompiledDirstateHelpersFeature.available():
811
if compiled_dirstate_helpers_feature.available():
814
812
from bzrlib._dirstate_helpers_pyx import update_entry
816
814
from bzrlib.dirstate import update_entry
817
815
self.assertIs(update_entry, dirstate.update_entry)
819
817
def test_process_entry(self):
820
if CompiledDirstateHelpersFeature.available():
818
if compiled_dirstate_helpers_feature.available():
821
819
from bzrlib._dirstate_helpers_pyx import ProcessEntryC
822
820
self.assertIs(ProcessEntryC, dirstate._process_entry)
1296
1294
self.assertEqual(sorted(expected), sorted(file_ids))
1296
def test_exceptions_raised(self):
1297
# This is a direct test of bug #495023, it relies on osutils.is_inside
1298
# getting called in an inner function. Which makes it a bit brittle,
1299
# but at least it does reproduce the bug.
1300
def is_inside_raises(*args, **kwargs):
1301
raise RuntimeError('stop this')
1302
tree = self.make_branch_and_tree('tree')
1303
self.build_tree(['tree/file', 'tree/dir/', 'tree/dir/sub',
1304
'tree/dir2/', 'tree/dir2/sub2'])
1305
tree.add(['file', 'dir', 'dir/sub', 'dir2', 'dir2/sub2'])
1306
tree.commit('first commit')
1308
self.addCleanup(tree.unlock)
1309
basis_tree = tree.basis_tree()
1310
orig = osutils.is_inside
1311
self.addCleanup(setattr, osutils, 'is_inside', orig)
1312
osutils.is_inside = is_inside_raises
1313
self.assertListRaises(RuntimeError, tree.iter_changes, basis_tree)
1298
1315
def test_simple_changes(self):
1299
1316
tree = self.make_branch_and_tree('tree')
1300
1317
self.build_tree(['tree/file'])