/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

Rework test_script a little bit.


Don't allow someone to request a stdin request to echo.
Echo never reads from stdin, it just echos its arguments.
You use 'cat' if you want to read from stdin.

A few other fixes because the tests were using filenames
that are actually illegal on Windows, rather than just
nonexistant.


Change the exception handling for commands so that
unknown errors don't get silently squashed and then
turn into hard-to-debug errors later.

test_script now passes on Windows.

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
737
743
 
738
744
    def test_trailing_garbage(self):
739
745
        tree, state, expected = self.create_basic_dirstate()
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()
 
746
        # We can modify the file as long as it hasn't been read yet.
744
747
        f = open('dirstate', 'ab')
745
748
        try:
746
749
            # Add bogus trailing garbage
747
750
            f.write('bogus\n')
748
751
        finally:
749
752
            f.close()
750
 
            state.lock_read()
751
753
        e = self.assertRaises(errors.DirstateCorrupt,
752
754
                              state._read_dirblocks_if_needed)
753
755
        # Make sure we mention the bogus characters in the error
757
759
class TestCompiledReadDirblocks(TestReadDirblocks):
758
760
    """Test the pyrex implementation of _read_dirblocks"""
759
761
 
760
 
    _test_needs_features = [compiled_dirstate_helpers_feature]
 
762
    _test_needs_features = [CompiledDirstateHelpersFeature]
761
763
 
762
764
    def get_read_dirblocks(self):
763
765
        from bzrlib._dirstate_helpers_pyx import _read_dirblocks
773
775
    """
774
776
 
775
777
    def test_bisect_dirblock(self):
776
 
        if compiled_dirstate_helpers_feature.available():
 
778
        if CompiledDirstateHelpersFeature.available():
777
779
            from bzrlib._dirstate_helpers_pyx import bisect_dirblock
778
780
        else:
779
781
            from bzrlib._dirstate_helpers_py import bisect_dirblock
780
782
        self.assertIs(bisect_dirblock, dirstate.bisect_dirblock)
781
783
 
782
784
    def test__bisect_path_left(self):
783
 
        if compiled_dirstate_helpers_feature.available():
 
785
        if CompiledDirstateHelpersFeature.available():
784
786
            from bzrlib._dirstate_helpers_pyx import _bisect_path_left
785
787
        else:
786
788
            from bzrlib._dirstate_helpers_py import _bisect_path_left
787
789
        self.assertIs(_bisect_path_left, dirstate._bisect_path_left)
788
790
 
789
791
    def test__bisect_path_right(self):
790
 
        if compiled_dirstate_helpers_feature.available():
 
792
        if CompiledDirstateHelpersFeature.available():
791
793
            from bzrlib._dirstate_helpers_pyx import _bisect_path_right
792
794
        else:
793
795
            from bzrlib._dirstate_helpers_py import _bisect_path_right
794
796
        self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
795
797
 
796
798
    def test_cmp_by_dirs(self):
797
 
        if compiled_dirstate_helpers_feature.available():
 
799
        if CompiledDirstateHelpersFeature.available():
798
800
            from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
799
801
        else:
800
802
            from bzrlib._dirstate_helpers_py import cmp_by_dirs
801
803
        self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)
802
804
 
803
805
    def test__read_dirblocks(self):
804
 
        if compiled_dirstate_helpers_feature.available():
 
806
        if CompiledDirstateHelpersFeature.available():
805
807
            from bzrlib._dirstate_helpers_pyx import _read_dirblocks
806
808
        else:
807
809
            from bzrlib._dirstate_helpers_py import _read_dirblocks
808
810
        self.assertIs(_read_dirblocks, dirstate._read_dirblocks)
809
811
 
810
812
    def test_update_entry(self):
811
 
        if compiled_dirstate_helpers_feature.available():
 
813
        if CompiledDirstateHelpersFeature.available():
812
814
            from bzrlib._dirstate_helpers_pyx import update_entry
813
815
        else:
814
816
            from bzrlib.dirstate import update_entry
815
817
        self.assertIs(update_entry, dirstate.update_entry)
816
818
 
817
819
    def test_process_entry(self):
818
 
        if compiled_dirstate_helpers_feature.available():
 
820
        if CompiledDirstateHelpersFeature.available():
819
821
            from bzrlib._dirstate_helpers_pyx import ProcessEntryC
820
822
            self.assertIs(ProcessEntryC, dirstate._process_entry)
821
823
        else:
831
833
 
832
834
    def setUp(self):
833
835
        super(TestUpdateEntry, self).setUp()
834
 
        self.overrideAttr(dirstate, 'update_entry', self.update_entry)
 
836
        orig = dirstate.update_entry
 
837
        def cleanup():
 
838
            dirstate.update_entry = orig
 
839
        self.addCleanup(cleanup)
 
840
        dirstate.update_entry = self.update_entry
835
841
 
836
842
    def get_state_with_a(self):
837
843
        """Create a DirState tracking a single object named 'a'"""
1274
1280
 
1275
1281
    def setUp(self):
1276
1282
        super(TestProcessEntry, self).setUp()
1277
 
        self.overrideAttr(dirstate, '_process_entry', self._process_entry)
 
1283
        orig = dirstate._process_entry
 
1284
        def cleanup():
 
1285
            dirstate._process_entry = orig
 
1286
        self.addCleanup(cleanup)
 
1287
        dirstate._process_entry = self._process_entry
1278
1288
 
1279
1289
    def assertChangedFileIds(self, expected, tree):
1280
1290
        tree.lock_read()
1285
1295
            tree.unlock()
1286
1296
        self.assertEqual(sorted(expected), sorted(file_ids))
1287
1297
 
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
1298
    def test_simple_changes(self):
1306
1299
        tree = self.make_branch_and_tree('tree')
1307
1300
        self.build_tree(['tree/file'])