43
43
class TestBisectPathMixin(object):
44
"""Test that bisect_path_*() returns the expected values.
44
"""Test that _bisect_path_*() returns the expected values.
46
bisect_path_* is intended to work like bisect.bisect_*() except it
46
_bisect_path_* is intended to work like bisect.bisect_*() except it
47
47
knows it is working on paths that are sorted by ('path', 'to', 'foo')
48
48
chunks rather than by raw 'path/to/foo'.
51
51
def get_bisect_path(self):
52
"""Return an implementation of bisect_path_*"""
52
"""Return an implementation of _bisect_path_*"""
53
53
raise NotImplementedError
55
55
def get_bisect(self):
194
194
class TestBisectPathLeft(tests.TestCase, TestBisectPathMixin):
196
196
def get_bisect_path(self):
197
from bzrlib._dirstate_helpers_py import bisect_path_left_py
198
return bisect_path_left_py
197
from bzrlib._dirstate_helpers_py import _bisect_path_left_py
198
return _bisect_path_left_py
200
200
def get_bisect(self):
201
201
return bisect.bisect_left, 0
204
204
class TestCompiledBisectPathLeft(TestBisectPathLeft):
205
"""Test that bisect_path_left() returns the expected values.
205
"""Test that _bisect_path_left() returns the expected values.
207
207
This runs all the normal tests that TestBisectDirblock did, but uses the
208
208
compiled version.
211
211
_test_needs_features = [CompiledDirstateHelpersFeature]
213
213
def get_bisect_path(self):
214
from bzrlib._dirstate_helpers_c import bisect_path_left_c
215
return bisect_path_left_c
214
from bzrlib._dirstate_helpers_c import _bisect_path_left_c
215
return _bisect_path_left_c
218
218
class TestBisectPathRight(tests.TestCase, TestBisectPathMixin):
220
220
def get_bisect_path(self):
221
from bzrlib._dirstate_helpers_py import bisect_path_right_py
222
return bisect_path_right_py
221
from bzrlib._dirstate_helpers_py import _bisect_path_right_py
222
return _bisect_path_right_py
224
224
def get_bisect(self):
225
225
return bisect.bisect_right, -1
228
228
class TestCompiledBisectPathRight(TestBisectPathRight):
229
"""Test that bisect_path_right() returns the expected values.
229
"""Test that _bisect_path_right() returns the expected values.
231
231
This runs all the normal tests that TestBisectDirblock did, but uses the
232
232
compiled version.
235
235
_test_needs_features = [CompiledDirstateHelpersFeature]
237
237
def get_bisect_path(self):
238
from bzrlib._dirstate_helpers_c import bisect_path_right_c
239
return bisect_path_right_c
238
from bzrlib._dirstate_helpers_c import _bisect_path_right_c
239
return _bisect_path_right_c
242
242
class TestBisectDirblock(tests.TestCase):
459
459
class TestCmpPathByDirblock(tests.TestCase):
461
461
def get_cmp_path_by_dirblock(self):
462
"""Get a specific implementation of cmp_path_by_dirblock."""
463
from bzrlib._dirstate_helpers_py import cmp_path_by_dirblock_py
464
return cmp_path_by_dirblock_py
462
"""Get a specific implementation of _cmp_path_by_dirblock."""
463
from bzrlib._dirstate_helpers_py import _cmp_path_by_dirblock_py
464
return _cmp_path_by_dirblock_py
466
466
def assertCmpPathByDirblock(self, paths):
467
467
"""Compare all paths and make sure they evaluate to the correct order.
565
565
class TestCompiledCmpPathByDirblock(TestCmpPathByDirblock):
566
"""Test the pyrex implementation of cmp_path_by_dirblock"""
566
"""Test the pyrex implementation of _cmp_path_by_dirblock"""
568
568
_test_needs_features = [CompiledDirstateHelpersFeature]
570
570
def get_cmp_by_dirs(self):
571
from bzrlib._dirstate_helpers_c import cmp_path_by_dirblock_c
572
return cmp_path_by_dirblock_c
571
from bzrlib._dirstate_helpers_c import _cmp_path_by_dirblock_c
572
return _cmp_path_by_dirblock_c
575
575
class TestMemRChr(tests.TestCase):
576
"""Test the pyrex implementation of cmp_path_by_dirblock"""
576
"""Test memrchr functionality"""
578
578
_test_needs_features = [CompiledDirstateHelpersFeature]
641
641
def get_read_dirblocks(self):
642
642
from bzrlib._dirstate_helpers_c import _read_dirblocks_c
643
643
return _read_dirblocks_c
646
class TestUsingCompiledIfAvailable(tests.TestCase):
647
"""Check that any compiled functions that are available are the default.
649
It is possible to have typos, etc in the import line, such that
650
_dirstate_helpers_c is actually available, but the compiled functions are
654
def test_bisect_dirblock(self):
655
if CompiledDirstateHelpersFeature.available():
656
from bzrlib._dirstate_helpers_c import bisect_dirblock_c
657
self.assertIs(bisect_dirblock_c, dirstate.bisect_dirblock)
659
from bzrlib._dirstate_helpers_py import bisect_dirblock_py
660
self.assertIs(bisect_dirblock_py, dirstate.bisect_dirblock)
662
def test__bisect_path_left(self):
663
if CompiledDirstateHelpersFeature.available():
664
from bzrlib._dirstate_helpers_c import _bisect_path_left_c
665
self.assertIs(_bisect_path_left_c, dirstate._bisect_path_left)
667
from bzrlib._dirstate_helpers_py import _bisect_path_left_py
668
self.assertIs(_bisect_path_left_py, dirstate._bisect_path_left)
670
def test__bisect_path_right(self):
671
if CompiledDirstateHelpersFeature.available():
672
from bzrlib._dirstate_helpers_c import _bisect_path_right_c
673
self.assertIs(_bisect_path_right_c, dirstate._bisect_path_right)
675
from bzrlib._dirstate_helpers_py import _bisect_path_right_py
676
self.assertIs(_bisect_path_right_py, dirstate._bisect_path_right)
678
def test_cmp_by_dirs(self):
679
if CompiledDirstateHelpersFeature.available():
680
from bzrlib._dirstate_helpers_c import cmp_by_dirs_c
681
self.assertIs(cmp_by_dirs_c, dirstate.cmp_by_dirs)
683
from bzrlib._dirstate_helpers_py import cmp_by_dirs_py
684
self.assertIs(cmp_by_dirs_py, dirstate.cmp_by_dirs)
686
def test__read_dirblocks(self):
687
if CompiledDirstateHelpersFeature.available():
688
from bzrlib._dirstate_helpers_c import _read_dirblocks_c
689
self.assertIs(_read_dirblocks_c, dirstate._read_dirblocks)
691
from bzrlib._dirstate_helpers_py import _read_dirblocks_py
692
self.assertIs(_read_dirblocks_py, dirstate._read_dirblocks)