~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__dirstate_helpers.py

  • Committer: Aaron Bentley
  • Date: 2009-06-26 03:44:30 UTC
  • mfrom: (4481 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4482.
  • Revision ID: aaron@aaronbentley.com-20090626034430-5btbqa44ikywccsu
Merge bzr.dev into vpipe

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