~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__dirstate_helpers.py

  • Committer: John Arbash Meinel
  • Date: 2007-07-12 16:34:02 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070712163402-lp91q157w5etslrj
Some restructuring.
Move bisect_path_* to private functions
Move cmp_path_by_dirblock to a private function,
since it is only used by the bisect_path functions.
Add tests that the compiled versions are actually used.
This catches cases when the import fails for the wrong reason.
Move some code around to make it closer to sorted by name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
 
43
43
class TestBisectPathMixin(object):
44
 
    """Test that bisect_path_*() returns the expected values.
 
44
    """Test that _bisect_path_*() returns the expected values.
45
45
 
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'.
49
49
    """
50
50
 
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
54
54
 
55
55
    def get_bisect(self):
194
194
class TestBisectPathLeft(tests.TestCase, TestBisectPathMixin):
195
195
 
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
199
199
 
200
200
    def get_bisect(self):
201
201
        return bisect.bisect_left, 0
202
202
 
203
203
 
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.
206
206
 
207
207
    This runs all the normal tests that TestBisectDirblock did, but uses the
208
208
    compiled version.
211
211
    _test_needs_features = [CompiledDirstateHelpersFeature]
212
212
 
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
216
216
 
217
217
 
218
218
class TestBisectPathRight(tests.TestCase, TestBisectPathMixin):
219
219
 
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
223
223
 
224
224
    def get_bisect(self):
225
225
        return bisect.bisect_right, -1
226
226
 
227
227
 
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.
230
230
 
231
231
    This runs all the normal tests that TestBisectDirblock did, but uses the
232
232
    compiled version.
235
235
    _test_needs_features = [CompiledDirstateHelpersFeature]
236
236
 
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
240
240
 
241
241
 
242
242
class TestBisectDirblock(tests.TestCase):
459
459
class TestCmpPathByDirblock(tests.TestCase):
460
460
 
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
465
465
 
466
466
    def assertCmpPathByDirblock(self, paths):
467
467
        """Compare all paths and make sure they evaluate to the correct order.
563
563
 
564
564
 
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"""
567
567
 
568
568
    _test_needs_features = [CompiledDirstateHelpersFeature]
569
569
 
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
573
573
 
574
574
 
575
575
class TestMemRChr(tests.TestCase):
576
 
    """Test the pyrex implementation of cmp_path_by_dirblock"""
 
576
    """Test memrchr functionality"""
577
577
 
578
578
    _test_needs_features = [CompiledDirstateHelpersFeature]
579
579
 
641
641
    def get_read_dirblocks(self):
642
642
        from bzrlib._dirstate_helpers_c import _read_dirblocks_c
643
643
        return _read_dirblocks_c
 
644
 
 
645
 
 
646
class TestUsingCompiledIfAvailable(tests.TestCase):
 
647
    """Check that any compiled functions that are available are the default.
 
648
 
 
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
 
651
    not being used.
 
652
    """
 
653
 
 
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)
 
658
        else:
 
659
            from bzrlib._dirstate_helpers_py import bisect_dirblock_py
 
660
            self.assertIs(bisect_dirblock_py, dirstate.bisect_dirblock)
 
661
 
 
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)
 
666
        else:
 
667
            from bzrlib._dirstate_helpers_py import _bisect_path_left_py
 
668
            self.assertIs(_bisect_path_left_py, dirstate._bisect_path_left)
 
669
 
 
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)
 
674
        else:
 
675
            from bzrlib._dirstate_helpers_py import _bisect_path_right_py
 
676
            self.assertIs(_bisect_path_right_py, dirstate._bisect_path_right)
 
677
 
 
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)
 
682
        else:
 
683
            from bzrlib._dirstate_helpers_py import cmp_by_dirs_py
 
684
            self.assertIs(cmp_by_dirs_py, dirstate.cmp_by_dirs)
 
685
 
 
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)
 
690
        else:
 
691
            from bzrlib._dirstate_helpers_py import _read_dirblocks_py
 
692
            self.assertIs(_read_dirblocks_py, dirstate._read_dirblocks)
 
693