~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__dirstate_helpers.py

  • Committer: Matt Nordhoff
  • Date: 2009-06-23 05:12:07 UTC
  • mto: This revision was merged to the branch mainline in revision 4474.
  • Revision ID: mnordhoff@mattnordhoff.com-20090623051207-fksdtbzkwtnrw9dd
Update _add_text docstrings that still referred to add_text.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    )
33
33
 
34
34
try:
35
 
    from bzrlib import _dirstate_helpers_pyx
36
 
    has_dirstate_helpers_pyx = True
 
35
    from bzrlib import _dirstate_helpers_c
 
36
    has_dirstate_helpers_c = True
37
37
except ImportError:
38
 
    has_dirstate_helpers_pyx = False
 
38
    has_dirstate_helpers_c = False
39
39
 
40
40
 
41
41
class _CompiledDirstateHelpersFeature(tests.Feature):
42
42
    def _probe(self):
43
 
        return has_dirstate_helpers_pyx
 
43
        return has_dirstate_helpers_c
44
44
 
45
45
    def feature_name(self):
46
 
        return 'bzrlib._dirstate_helpers_pyx'
 
46
        return 'bzrlib._dirstate_helpers_c'
47
47
CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
48
48
 
49
49
 
56
56
 
57
57
    ue_scenarios = [('dirstate_Python',
58
58
                     {'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})
62
 
        ue_scenarios.append(pyrex_scenario)
 
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
63
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
64
64
        remaining_tests, tests.condition_isinstance(TestUpdateEntry))
65
65
    tests.multiply_tests(process_entry_tests,
69
69
 
70
70
    pe_scenarios = [('dirstate_Python',
71
71
                     {'_process_entry': dirstate.ProcessEntryPython})]
72
 
    if has_dirstate_helpers_pyx:
73
 
        pyrex_scenario = (
74
 
            'dirstate_Pyrex',
75
 
            {'_process_entry': _dirstate_helpers_pyx.ProcessEntryC})
76
 
        pe_scenarios.append(pyrex_scenario)
 
72
    if has_dirstate_helpers_c:
 
73
        c_scenario = ('dirstate_C',
 
74
                     {'_process_entry': _dirstate_helpers_c.ProcessEntryC})
 
75
        pe_scenarios.append(c_scenario)
77
76
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
78
77
        remaining_tests, tests.condition_isinstance(TestProcessEntry))
79
78
    tests.multiply_tests(process_entry_tests,
246
245
 
247
246
 
248
247
class TestBisectPathLeft(tests.TestCase, TestBisectPathMixin):
249
 
    """Run all Bisect Path tests against _bisect_path_left."""
 
248
    """Run all Bisect Path tests against _bisect_path_left_py."""
250
249
 
251
250
    def get_bisect_path(self):
252
 
        from bzrlib._dirstate_helpers_py import _bisect_path_left
253
 
        return _bisect_path_left
 
251
        from bzrlib._dirstate_helpers_py import _bisect_path_left_py
 
252
        return _bisect_path_left_py
254
253
 
255
254
    def get_bisect(self):
256
255
        return bisect.bisect_left, 0
257
256
 
258
257
 
259
258
class TestCompiledBisectPathLeft(TestBisectPathLeft):
260
 
    """Run all Bisect Path tests against _bisect_path_lect"""
 
259
    """Run all Bisect Path tests against _bisect_path_right_c"""
261
260
 
262
261
    _test_needs_features = [CompiledDirstateHelpersFeature]
263
262
 
264
263
    def get_bisect_path(self):
265
 
        from bzrlib._dirstate_helpers_pyx import _bisect_path_left
266
 
        return _bisect_path_left
 
264
        from bzrlib._dirstate_helpers_c import _bisect_path_left_c
 
265
        return _bisect_path_left_c
267
266
 
268
267
 
269
268
class TestBisectPathRight(tests.TestCase, TestBisectPathMixin):
270
 
    """Run all Bisect Path tests against _bisect_path_right"""
 
269
    """Run all Bisect Path tests against _bisect_path_right_py"""
271
270
 
272
271
    def get_bisect_path(self):
273
 
        from bzrlib._dirstate_helpers_py import _bisect_path_right
274
 
        return _bisect_path_right
 
272
        from bzrlib._dirstate_helpers_py import _bisect_path_right_py
 
273
        return _bisect_path_right_py
275
274
 
276
275
    def get_bisect(self):
277
276
        return bisect.bisect_right, -1
278
277
 
279
278
 
280
279
class TestCompiledBisectPathRight(TestBisectPathRight):
281
 
    """Run all Bisect Path tests against _bisect_path_right"""
 
280
    """Run all Bisect Path tests against _bisect_path_right_c"""
282
281
 
283
282
    _test_needs_features = [CompiledDirstateHelpersFeature]
284
283
 
285
284
    def get_bisect_path(self):
286
 
        from bzrlib._dirstate_helpers_pyx import _bisect_path_right
287
 
        return _bisect_path_right
 
285
        from bzrlib._dirstate_helpers_c import _bisect_path_right_c
 
286
        return _bisect_path_right_c
288
287
 
289
288
 
290
289
class TestBisectDirblock(tests.TestCase):
301
300
 
302
301
    def get_bisect_dirblock(self):
303
302
        """Return an implementation of bisect_dirblock"""
304
 
        from bzrlib._dirstate_helpers_py import bisect_dirblock
305
 
        return bisect_dirblock
 
303
        from bzrlib._dirstate_helpers_py import bisect_dirblock_py
 
304
        return bisect_dirblock_py
306
305
 
307
306
    def assertBisect(self, dirblocks, split_dirblocks, path, *args, **kwargs):
308
307
        """Assert that bisect_split works like bisect_left on the split paths.
395
394
    _test_needs_features = [CompiledDirstateHelpersFeature]
396
395
 
397
396
    def get_bisect_dirblock(self):
398
 
        from bzrlib._dirstate_helpers_pyx import bisect_dirblock
399
 
        return bisect_dirblock
 
397
        from bzrlib._dirstate_helpers_c import bisect_dirblock_c
 
398
        return bisect_dirblock_c
400
399
 
401
400
 
402
401
class TestCmpByDirs(tests.TestCase):
411
410
 
412
411
    def get_cmp_by_dirs(self):
413
412
        """Get a specific implementation of cmp_by_dirs."""
414
 
        from bzrlib._dirstate_helpers_py import cmp_by_dirs
415
 
        return cmp_by_dirs
 
413
        from bzrlib._dirstate_helpers_py import cmp_by_dirs_py
 
414
        return cmp_by_dirs_py
416
415
 
417
416
    def assertCmpByDirs(self, expected, str1, str2):
418
417
        """Compare the two strings, in both directions.
517
516
    _test_needs_features = [CompiledDirstateHelpersFeature]
518
517
 
519
518
    def get_cmp_by_dirs(self):
520
 
        from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
521
 
        return cmp_by_dirs
 
519
        from bzrlib._dirstate_helpers_c import cmp_by_dirs_c
 
520
        return cmp_by_dirs_c
522
521
 
523
522
 
524
523
class TestCmpPathByDirblock(tests.TestCase):
533
532
 
534
533
    def get_cmp_path_by_dirblock(self):
535
534
        """Get a specific implementation of _cmp_path_by_dirblock."""
536
 
        from bzrlib._dirstate_helpers_py import _cmp_path_by_dirblock
537
 
        return _cmp_path_by_dirblock
 
535
        from bzrlib._dirstate_helpers_py import _cmp_path_by_dirblock_py
 
536
        return _cmp_path_by_dirblock_py
538
537
 
539
538
    def assertCmpPathByDirblock(self, paths):
540
539
        """Compare all paths and make sure they evaluate to the correct order.
668
667
    _test_needs_features = [CompiledDirstateHelpersFeature]
669
668
 
670
669
    def get_cmp_by_dirs(self):
671
 
        from bzrlib._dirstate_helpers_pyx import _cmp_path_by_dirblock
672
 
        return _cmp_path_by_dirblock
 
670
        from bzrlib._dirstate_helpers_c import _cmp_path_by_dirblock_c
 
671
        return _cmp_path_by_dirblock_c
673
672
 
674
673
 
675
674
class TestMemRChr(tests.TestCase):
678
677
    _test_needs_features = [CompiledDirstateHelpersFeature]
679
678
 
680
679
    def assertMemRChr(self, expected, s, c):
681
 
        from bzrlib._dirstate_helpers_pyx import _py_memrchr
 
680
        from bzrlib._dirstate_helpers_c import _py_memrchr
682
681
        self.assertEqual(expected, _py_memrchr(s, c))
683
682
 
684
683
    def test_missing(self):
726
725
    """
727
726
 
728
727
    def get_read_dirblocks(self):
729
 
        from bzrlib._dirstate_helpers_py import _read_dirblocks
730
 
        return _read_dirblocks
 
728
        from bzrlib._dirstate_helpers_py import _read_dirblocks_py
 
729
        return _read_dirblocks_py
731
730
 
732
731
    def test_smoketest(self):
733
732
        """Make sure that we can create and read back a simple file."""
762
761
    _test_needs_features = [CompiledDirstateHelpersFeature]
763
762
 
764
763
    def get_read_dirblocks(self):
765
 
        from bzrlib._dirstate_helpers_pyx import _read_dirblocks
766
 
        return _read_dirblocks
 
764
        from bzrlib._dirstate_helpers_c import _read_dirblocks_c
 
765
        return _read_dirblocks_c
767
766
 
768
767
 
769
768
class TestUsingCompiledIfAvailable(tests.TestCase):
770
769
    """Check that any compiled functions that are available are the default.
771
770
 
772
771
    It is possible to have typos, etc in the import line, such that
773
 
    _dirstate_helpers_pyx is actually available, but the compiled functions are
 
772
    _dirstate_helpers_c is actually available, but the compiled functions are
774
773
    not being used.
775
774
    """
776
775
 
777
776
    def test_bisect_dirblock(self):
778
777
        if CompiledDirstateHelpersFeature.available():
779
 
            from bzrlib._dirstate_helpers_pyx import bisect_dirblock
 
778
            from bzrlib._dirstate_helpers_c import bisect_dirblock_c
 
779
            self.assertIs(bisect_dirblock_c, dirstate.bisect_dirblock)
780
780
        else:
781
 
            from bzrlib._dirstate_helpers_py import bisect_dirblock
782
 
        self.assertIs(bisect_dirblock, dirstate.bisect_dirblock)
 
781
            from bzrlib._dirstate_helpers_py import bisect_dirblock_py
 
782
            self.assertIs(bisect_dirblock_py, dirstate.bisect_dirblock)
783
783
 
784
784
    def test__bisect_path_left(self):
785
785
        if CompiledDirstateHelpersFeature.available():
786
 
            from bzrlib._dirstate_helpers_pyx import _bisect_path_left
 
786
            from bzrlib._dirstate_helpers_c import _bisect_path_left_c
 
787
            self.assertIs(_bisect_path_left_c, dirstate._bisect_path_left)
787
788
        else:
788
 
            from bzrlib._dirstate_helpers_py import _bisect_path_left
789
 
        self.assertIs(_bisect_path_left, dirstate._bisect_path_left)
 
789
            from bzrlib._dirstate_helpers_py import _bisect_path_left_py
 
790
            self.assertIs(_bisect_path_left_py, dirstate._bisect_path_left)
790
791
 
791
792
    def test__bisect_path_right(self):
792
793
        if CompiledDirstateHelpersFeature.available():
793
 
            from bzrlib._dirstate_helpers_pyx import _bisect_path_right
 
794
            from bzrlib._dirstate_helpers_c import _bisect_path_right_c
 
795
            self.assertIs(_bisect_path_right_c, dirstate._bisect_path_right)
794
796
        else:
795
 
            from bzrlib._dirstate_helpers_py import _bisect_path_right
796
 
        self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
 
797
            from bzrlib._dirstate_helpers_py import _bisect_path_right_py
 
798
            self.assertIs(_bisect_path_right_py, dirstate._bisect_path_right)
797
799
 
798
800
    def test_cmp_by_dirs(self):
799
801
        if CompiledDirstateHelpersFeature.available():
800
 
            from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
 
802
            from bzrlib._dirstate_helpers_c import cmp_by_dirs_c
 
803
            self.assertIs(cmp_by_dirs_c, dirstate.cmp_by_dirs)
801
804
        else:
802
 
            from bzrlib._dirstate_helpers_py import cmp_by_dirs
803
 
        self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)
 
805
            from bzrlib._dirstate_helpers_py import cmp_by_dirs_py
 
806
            self.assertIs(cmp_by_dirs_py, dirstate.cmp_by_dirs)
804
807
 
805
808
    def test__read_dirblocks(self):
806
809
        if CompiledDirstateHelpersFeature.available():
807
 
            from bzrlib._dirstate_helpers_pyx import _read_dirblocks
 
810
            from bzrlib._dirstate_helpers_c import _read_dirblocks_c
 
811
            self.assertIs(_read_dirblocks_c, dirstate._read_dirblocks)
808
812
        else:
809
 
            from bzrlib._dirstate_helpers_py import _read_dirblocks
810
 
        self.assertIs(_read_dirblocks, dirstate._read_dirblocks)
 
813
            from bzrlib._dirstate_helpers_py import _read_dirblocks_py
 
814
            self.assertIs(_read_dirblocks_py, dirstate._read_dirblocks)
811
815
 
812
816
    def test_update_entry(self):
813
817
        if CompiledDirstateHelpersFeature.available():
814
 
            from bzrlib._dirstate_helpers_pyx import update_entry
 
818
            from bzrlib._dirstate_helpers_c import update_entry
 
819
            self.assertIs(update_entry, dirstate.update_entry)
815
820
        else:
816
 
            from bzrlib.dirstate import update_entry
817
 
        self.assertIs(update_entry, dirstate.update_entry)
 
821
            from bzrlib.dirstate import py_update_entry
 
822
            self.assertIs(py_update_entry, dirstate.py_update_entry)
818
823
 
819
824
    def test_process_entry(self):
820
825
        if CompiledDirstateHelpersFeature.available():
821
 
            from bzrlib._dirstate_helpers_pyx import ProcessEntryC
 
826
            from bzrlib._dirstate_helpers_c import ProcessEntryC
822
827
            self.assertIs(ProcessEntryC, dirstate._process_entry)
823
828
        else:
824
829
            from bzrlib.dirstate import ProcessEntryPython