~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: 2010-02-17 17:11:16 UTC
  • mfrom: (4797.2.17 2.1)
  • mto: (4797.2.18 2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: john@arbash-meinel.com-20100217171116-h7t9223ystbnx5h8
merge bzr.2.1 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
 
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()
 
41
compiled_dirstate_helpers_feature = tests.ModuleAvailableFeature(
 
42
                                'bzrlib._dirstate_helpers_pyx')
48
43
 
49
44
 
50
45
def load_tests(basic_tests, module, loader):
56
51
 
57
52
    ue_scenarios = [('dirstate_Python',
58
53
                     {'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})
 
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})
62
57
        ue_scenarios.append(pyrex_scenario)
63
58
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
64
59
        remaining_tests, tests.condition_isinstance(TestUpdateEntry))
69
64
 
70
65
    pe_scenarios = [('dirstate_Python',
71
66
                     {'_process_entry': dirstate.ProcessEntryPython})]
72
 
    if has_dirstate_helpers_pyx:
73
 
        pyrex_scenario = (
74
 
            'dirstate_Pyrex',
75
 
            {'_process_entry': _dirstate_helpers_pyx.ProcessEntryC})
 
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})
76
70
        pe_scenarios.append(pyrex_scenario)
77
71
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
78
72
        remaining_tests, tests.condition_isinstance(TestProcessEntry))
259
253
class TestCompiledBisectPathLeft(TestBisectPathLeft):
260
254
    """Run all Bisect Path tests against _bisect_path_lect"""
261
255
 
262
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
 
256
    _test_needs_features = [compiled_dirstate_helpers_feature]
263
257
 
264
258
    def get_bisect_path(self):
265
259
        from bzrlib._dirstate_helpers_pyx import _bisect_path_left
280
274
class TestCompiledBisectPathRight(TestBisectPathRight):
281
275
    """Run all Bisect Path tests against _bisect_path_right"""
282
276
 
283
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
 
277
    _test_needs_features = [compiled_dirstate_helpers_feature]
284
278
 
285
279
    def get_bisect_path(self):
286
280
        from bzrlib._dirstate_helpers_pyx import _bisect_path_right
392
386
    compiled version.
393
387
    """
394
388
 
395
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
 
389
    _test_needs_features = [compiled_dirstate_helpers_feature]
396
390
 
397
391
    def get_bisect_dirblock(self):
398
392
        from bzrlib._dirstate_helpers_pyx import bisect_dirblock
514
508
class TestCompiledCmpByDirs(TestCmpByDirs):
515
509
    """Test the pyrex implementation of cmp_by_dirs"""
516
510
 
517
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
 
511
    _test_needs_features = [compiled_dirstate_helpers_feature]
518
512
 
519
513
    def get_cmp_by_dirs(self):
520
514
        from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
665
659
class TestCompiledCmpPathByDirblock(TestCmpPathByDirblock):
666
660
    """Test the pyrex implementation of _cmp_path_by_dirblock"""
667
661
 
668
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
 
662
    _test_needs_features = [compiled_dirstate_helpers_feature]
669
663
 
670
664
    def get_cmp_by_dirs(self):
671
665
        from bzrlib._dirstate_helpers_pyx import _cmp_path_by_dirblock
675
669
class TestMemRChr(tests.TestCase):
676
670
    """Test memrchr functionality"""
677
671
 
678
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
 
672
    _test_needs_features = [compiled_dirstate_helpers_feature]
679
673
 
680
674
    def assertMemRChr(self, expected, s, c):
681
675
        from bzrlib._dirstate_helpers_pyx import _py_memrchr
743
737
 
744
738
    def test_trailing_garbage(self):
745
739
        tree, state, expected = self.create_basic_dirstate()
746
 
        # We can modify the file as long as it hasn't been read yet.
 
740
        # On Linux, we can write extra data as long as we haven't read yet, but
 
741
        # on Win32, if you've opened the file with FILE_SHARE_READ, trying to
 
742
        # open it in append mode will fail.
 
743
        state.unlock()
747
744
        f = open('dirstate', 'ab')
748
745
        try:
749
746
            # Add bogus trailing garbage
750
747
            f.write('bogus\n')
751
748
        finally:
752
749
            f.close()
 
750
            state.lock_read()
753
751
        e = self.assertRaises(errors.DirstateCorrupt,
754
752
                              state._read_dirblocks_if_needed)
755
753
        # Make sure we mention the bogus characters in the error
759
757
class TestCompiledReadDirblocks(TestReadDirblocks):
760
758
    """Test the pyrex implementation of _read_dirblocks"""
761
759
 
762
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
 
760
    _test_needs_features = [compiled_dirstate_helpers_feature]
763
761
 
764
762
    def get_read_dirblocks(self):
765
763
        from bzrlib._dirstate_helpers_pyx import _read_dirblocks
775
773
    """
776
774
 
777
775
    def test_bisect_dirblock(self):
778
 
        if CompiledDirstateHelpersFeature.available():
 
776
        if compiled_dirstate_helpers_feature.available():
779
777
            from bzrlib._dirstate_helpers_pyx import bisect_dirblock
780
778
        else:
781
779
            from bzrlib._dirstate_helpers_py import bisect_dirblock
782
780
        self.assertIs(bisect_dirblock, dirstate.bisect_dirblock)
783
781
 
784
782
    def test__bisect_path_left(self):
785
 
        if CompiledDirstateHelpersFeature.available():
 
783
        if compiled_dirstate_helpers_feature.available():
786
784
            from bzrlib._dirstate_helpers_pyx import _bisect_path_left
787
785
        else:
788
786
            from bzrlib._dirstate_helpers_py import _bisect_path_left
789
787
        self.assertIs(_bisect_path_left, dirstate._bisect_path_left)
790
788
 
791
789
    def test__bisect_path_right(self):
792
 
        if CompiledDirstateHelpersFeature.available():
 
790
        if compiled_dirstate_helpers_feature.available():
793
791
            from bzrlib._dirstate_helpers_pyx import _bisect_path_right
794
792
        else:
795
793
            from bzrlib._dirstate_helpers_py import _bisect_path_right
796
794
        self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
797
795
 
798
796
    def test_cmp_by_dirs(self):
799
 
        if CompiledDirstateHelpersFeature.available():
 
797
        if compiled_dirstate_helpers_feature.available():
800
798
            from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
801
799
        else:
802
800
            from bzrlib._dirstate_helpers_py import cmp_by_dirs
803
801
        self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)
804
802
 
805
803
    def test__read_dirblocks(self):
806
 
        if CompiledDirstateHelpersFeature.available():
 
804
        if compiled_dirstate_helpers_feature.available():
807
805
            from bzrlib._dirstate_helpers_pyx import _read_dirblocks
808
806
        else:
809
807
            from bzrlib._dirstate_helpers_py import _read_dirblocks
810
808
        self.assertIs(_read_dirblocks, dirstate._read_dirblocks)
811
809
 
812
810
    def test_update_entry(self):
813
 
        if CompiledDirstateHelpersFeature.available():
 
811
        if compiled_dirstate_helpers_feature.available():
814
812
            from bzrlib._dirstate_helpers_pyx import update_entry
815
813
        else:
816
814
            from bzrlib.dirstate import update_entry
817
815
        self.assertIs(update_entry, dirstate.update_entry)
818
816
 
819
817
    def test_process_entry(self):
820
 
        if CompiledDirstateHelpersFeature.available():
 
818
        if compiled_dirstate_helpers_feature.available():
821
819
            from bzrlib._dirstate_helpers_pyx import ProcessEntryC
822
820
            self.assertIs(ProcessEntryC, dirstate._process_entry)
823
821
        else:
1295
1293
            tree.unlock()
1296
1294
        self.assertEqual(sorted(expected), sorted(file_ids))
1297
1295
 
 
1296
    def test_exceptions_raised(self):
 
1297
        # This is a direct test of bug #495023, it relies on osutils.is_inside
 
1298
        # getting called in an inner function. Which makes it a bit brittle,
 
1299
        # but at least it does reproduce the bug.
 
1300
        def is_inside_raises(*args, **kwargs):
 
1301
            raise RuntimeError('stop this')
 
1302
        tree = self.make_branch_and_tree('tree')
 
1303
        self.build_tree(['tree/file', 'tree/dir/', 'tree/dir/sub',
 
1304
                         'tree/dir2/', 'tree/dir2/sub2'])
 
1305
        tree.add(['file', 'dir', 'dir/sub', 'dir2', 'dir2/sub2'])
 
1306
        tree.commit('first commit')
 
1307
        tree.lock_read()
 
1308
        self.addCleanup(tree.unlock)
 
1309
        basis_tree = tree.basis_tree()
 
1310
        orig = osutils.is_inside
 
1311
        self.addCleanup(setattr, osutils, 'is_inside', orig)
 
1312
        osutils.is_inside = is_inside_raises
 
1313
        self.assertListRaises(RuntimeError, tree.iter_changes, basis_tree)
 
1314
 
1298
1315
    def test_simple_changes(self):
1299
1316
        tree = self.make_branch_and_tree('tree')
1300
1317
        self.build_tree(['tree/file'])