/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__dirstate_helpers.py

  • Committer: Martin Pool
  • Date: 2009-12-10 00:13:16 UTC
  • mto: This revision was merged to the branch mainline in revision 4884.
  • Revision ID: mbp@sourcefrog.net-20091210001316-w1l2jtek6v8iyg49
Mention GNU project in --version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
38
38
    has_dirstate_helpers_pyx = False
39
39
 
40
40
 
41
 
compiled_dirstate_helpers_feature = tests.ModuleAvailableFeature(
42
 
                                'bzrlib._dirstate_helpers_pyx')
 
41
class _CompiledDirstateHelpersFeature(tests.Feature):
 
42
    def _probe(self):
 
43
        return has_dirstate_helpers_pyx
 
44
 
 
45
    def feature_name(self):
 
46
        return 'bzrlib._dirstate_helpers_pyx'
 
47
CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
43
48
 
44
49
 
45
50
def load_tests(basic_tests, module, loader):
51
56
 
52
57
    ue_scenarios = [('dirstate_Python',
53
58
                     {'update_entry': dirstate.py_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})
 
59
    if has_dirstate_helpers_pyx:
 
60
        pyrex_scenario = ('dirstate_Pyrex',
 
61
                          {'update_entry': _dirstate_helpers_pyx.update_entry})
57
62
        ue_scenarios.append(pyrex_scenario)
58
63
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
59
64
        remaining_tests, tests.condition_isinstance(TestUpdateEntry))
64
69
 
65
70
    pe_scenarios = [('dirstate_Python',
66
71
                     {'_process_entry': dirstate.ProcessEntryPython})]
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})
 
72
    if has_dirstate_helpers_pyx:
 
73
        pyrex_scenario = (
 
74
            'dirstate_Pyrex',
 
75
            {'_process_entry': _dirstate_helpers_pyx.ProcessEntryC})
70
76
        pe_scenarios.append(pyrex_scenario)
71
77
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
72
78
        remaining_tests, tests.condition_isinstance(TestProcessEntry))
253
259
class TestCompiledBisectPathLeft(TestBisectPathLeft):
254
260
    """Run all Bisect Path tests against _bisect_path_lect"""
255
261
 
256
 
    _test_needs_features = [compiled_dirstate_helpers_feature]
 
262
    _test_needs_features = [CompiledDirstateHelpersFeature]
257
263
 
258
264
    def get_bisect_path(self):
259
265
        from bzrlib._dirstate_helpers_pyx import _bisect_path_left
274
280
class TestCompiledBisectPathRight(TestBisectPathRight):
275
281
    """Run all Bisect Path tests against _bisect_path_right"""
276
282
 
277
 
    _test_needs_features = [compiled_dirstate_helpers_feature]
 
283
    _test_needs_features = [CompiledDirstateHelpersFeature]
278
284
 
279
285
    def get_bisect_path(self):
280
286
        from bzrlib._dirstate_helpers_pyx import _bisect_path_right
386
392
    compiled version.
387
393
    """
388
394
 
389
 
    _test_needs_features = [compiled_dirstate_helpers_feature]
 
395
    _test_needs_features = [CompiledDirstateHelpersFeature]
390
396
 
391
397
    def get_bisect_dirblock(self):
392
398
        from bzrlib._dirstate_helpers_pyx import bisect_dirblock
508
514
class TestCompiledCmpByDirs(TestCmpByDirs):
509
515
    """Test the pyrex implementation of cmp_by_dirs"""
510
516
 
511
 
    _test_needs_features = [compiled_dirstate_helpers_feature]
 
517
    _test_needs_features = [CompiledDirstateHelpersFeature]
512
518
 
513
519
    def get_cmp_by_dirs(self):
514
520
        from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
659
665
class TestCompiledCmpPathByDirblock(TestCmpPathByDirblock):
660
666
    """Test the pyrex implementation of _cmp_path_by_dirblock"""
661
667
 
662
 
    _test_needs_features = [compiled_dirstate_helpers_feature]
 
668
    _test_needs_features = [CompiledDirstateHelpersFeature]
663
669
 
664
670
    def get_cmp_by_dirs(self):
665
671
        from bzrlib._dirstate_helpers_pyx import _cmp_path_by_dirblock
669
675
class TestMemRChr(tests.TestCase):
670
676
    """Test memrchr functionality"""
671
677
 
672
 
    _test_needs_features = [compiled_dirstate_helpers_feature]
 
678
    _test_needs_features = [CompiledDirstateHelpersFeature]
673
679
 
674
680
    def assertMemRChr(self, expected, s, c):
675
681
        from bzrlib._dirstate_helpers_pyx import _py_memrchr
757
763
class TestCompiledReadDirblocks(TestReadDirblocks):
758
764
    """Test the pyrex implementation of _read_dirblocks"""
759
765
 
760
 
    _test_needs_features = [compiled_dirstate_helpers_feature]
 
766
    _test_needs_features = [CompiledDirstateHelpersFeature]
761
767
 
762
768
    def get_read_dirblocks(self):
763
769
        from bzrlib._dirstate_helpers_pyx import _read_dirblocks
773
779
    """
774
780
 
775
781
    def test_bisect_dirblock(self):
776
 
        if compiled_dirstate_helpers_feature.available():
 
782
        if CompiledDirstateHelpersFeature.available():
777
783
            from bzrlib._dirstate_helpers_pyx import bisect_dirblock
778
784
        else:
779
785
            from bzrlib._dirstate_helpers_py import bisect_dirblock
780
786
        self.assertIs(bisect_dirblock, dirstate.bisect_dirblock)
781
787
 
782
788
    def test__bisect_path_left(self):
783
 
        if compiled_dirstate_helpers_feature.available():
 
789
        if CompiledDirstateHelpersFeature.available():
784
790
            from bzrlib._dirstate_helpers_pyx import _bisect_path_left
785
791
        else:
786
792
            from bzrlib._dirstate_helpers_py import _bisect_path_left
787
793
        self.assertIs(_bisect_path_left, dirstate._bisect_path_left)
788
794
 
789
795
    def test__bisect_path_right(self):
790
 
        if compiled_dirstate_helpers_feature.available():
 
796
        if CompiledDirstateHelpersFeature.available():
791
797
            from bzrlib._dirstate_helpers_pyx import _bisect_path_right
792
798
        else:
793
799
            from bzrlib._dirstate_helpers_py import _bisect_path_right
794
800
        self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
795
801
 
796
802
    def test_cmp_by_dirs(self):
797
 
        if compiled_dirstate_helpers_feature.available():
 
803
        if CompiledDirstateHelpersFeature.available():
798
804
            from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
799
805
        else:
800
806
            from bzrlib._dirstate_helpers_py import cmp_by_dirs
801
807
        self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)
802
808
 
803
809
    def test__read_dirblocks(self):
804
 
        if compiled_dirstate_helpers_feature.available():
 
810
        if CompiledDirstateHelpersFeature.available():
805
811
            from bzrlib._dirstate_helpers_pyx import _read_dirblocks
806
812
        else:
807
813
            from bzrlib._dirstate_helpers_py import _read_dirblocks
808
814
        self.assertIs(_read_dirblocks, dirstate._read_dirblocks)
809
815
 
810
816
    def test_update_entry(self):
811
 
        if compiled_dirstate_helpers_feature.available():
 
817
        if CompiledDirstateHelpersFeature.available():
812
818
            from bzrlib._dirstate_helpers_pyx import update_entry
813
819
        else:
814
820
            from bzrlib.dirstate import update_entry
815
821
        self.assertIs(update_entry, dirstate.update_entry)
816
822
 
817
823
    def test_process_entry(self):
818
 
        if compiled_dirstate_helpers_feature.available():
 
824
        if CompiledDirstateHelpersFeature.available():
819
825
            from bzrlib._dirstate_helpers_pyx import ProcessEntryC
820
826
            self.assertIs(ProcessEntryC, dirstate._process_entry)
821
827
        else:
831
837
 
832
838
    def setUp(self):
833
839
        super(TestUpdateEntry, self).setUp()
834
 
        self.overrideAttr(dirstate, 'update_entry', self.update_entry)
 
840
        orig = dirstate.update_entry
 
841
        def cleanup():
 
842
            dirstate.update_entry = orig
 
843
        self.addCleanup(cleanup)
 
844
        dirstate.update_entry = self.update_entry
835
845
 
836
846
    def get_state_with_a(self):
837
847
        """Create a DirState tracking a single object named 'a'"""
1274
1284
 
1275
1285
    def setUp(self):
1276
1286
        super(TestProcessEntry, self).setUp()
1277
 
        self.overrideAttr(dirstate, '_process_entry', self._process_entry)
 
1287
        orig = dirstate._process_entry
 
1288
        def cleanup():
 
1289
            dirstate._process_entry = orig
 
1290
        self.addCleanup(cleanup)
 
1291
        dirstate._process_entry = self._process_entry
1278
1292
 
1279
1293
    def assertChangedFileIds(self, expected, tree):
1280
1294
        tree.lock_read()
1285
1299
            tree.unlock()
1286
1300
        self.assertEqual(sorted(expected), sorted(file_ids))
1287
1301
 
1288
 
    def test_exceptions_raised(self):
1289
 
        # This is a direct test of bug #495023, it relies on osutils.is_inside
1290
 
        # getting called in an inner function. Which makes it a bit brittle,
1291
 
        # but at least it does reproduce the bug.
1292
 
        tree = self.make_branch_and_tree('tree')
1293
 
        self.build_tree(['tree/file', 'tree/dir/', 'tree/dir/sub',
1294
 
                         'tree/dir2/', 'tree/dir2/sub2'])
1295
 
        tree.add(['file', 'dir', 'dir/sub', 'dir2', 'dir2/sub2'])
1296
 
        tree.commit('first commit')
1297
 
        tree.lock_read()
1298
 
        self.addCleanup(tree.unlock)
1299
 
        basis_tree = tree.basis_tree()
1300
 
        def is_inside_raises(*args, **kwargs):
1301
 
            raise RuntimeError('stop this')
1302
 
        self.overrideAttr(osutils, 'is_inside', is_inside_raises)
1303
 
        self.assertListRaises(RuntimeError, tree.iter_changes, basis_tree)
1304
 
 
1305
1302
    def test_simple_changes(self):
1306
1303
        tree = self.make_branch_and_tree('tree')
1307
1304
        self.build_tree(['tree/file'])