~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-08-13 19:08:57 UTC
  • mto: (5050.17.7 2.2)
  • mto: This revision was merged to the branch mainline in revision 5379.
  • Revision ID: john@arbash-meinel.com-20100813190857-mvzwnimrxvm0zimp
Lots of documentation updates.

We had a lot of http links pointing to the old domain. They should
all now be properly updated to the new domain. (only bazaar-vcs.org
entry left is for pqm, which seems to still reside at the old url.)

Also removed one 'TODO' doc entry about switching to binary xdelta, since
we basically did just that with groupcompress.

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 Unix, 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:
833
831
 
834
832
    def setUp(self):
835
833
        super(TestUpdateEntry, self).setUp()
836
 
        orig = dirstate.update_entry
837
 
        def cleanup():
838
 
            dirstate.update_entry = orig
839
 
        self.addCleanup(cleanup)
840
 
        dirstate.update_entry = self.update_entry
 
834
        self.overrideAttr(dirstate, 'update_entry', self.update_entry)
841
835
 
842
836
    def get_state_with_a(self):
843
837
        """Create a DirState tracking a single object named 'a'"""
1280
1274
 
1281
1275
    def setUp(self):
1282
1276
        super(TestProcessEntry, self).setUp()
1283
 
        orig = dirstate._process_entry
1284
 
        def cleanup():
1285
 
            dirstate._process_entry = orig
1286
 
        self.addCleanup(cleanup)
1287
 
        dirstate._process_entry = self._process_entry
 
1277
        self.overrideAttr(dirstate, '_process_entry', self._process_entry)
1288
1278
 
1289
1279
    def assertChangedFileIds(self, expected, tree):
1290
1280
        tree.lock_read()
1295
1285
            tree.unlock()
1296
1286
        self.assertEqual(sorted(expected), sorted(file_ids))
1297
1287
 
 
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
 
1298
1305
    def test_simple_changes(self):
1299
1306
        tree = self.make_branch_and_tree('tree')
1300
1307
        self.build_tree(['tree/file'])