~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

Streamline _walkdirs_utf8 for utf8 file systems, reducing time to traverse a mozilla tree from 1s to .6 seconds. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
from bzrlib.tests.test__walkdirs_win32 import Win32ReadDirFeature
58
58
 
59
59
 
60
 
def load_tests(standard_tests, module, loader):
61
 
    """Parameterize readdir tests."""
62
 
    to_adapt, result = split_suite_by_re(standard_tests, "readdir")
63
 
    adapter = TestScenarioApplier()
64
 
    from bzrlib import _readdir_py
65
 
    adapter.scenarios = [('python', {'read_dir': _readdir_py.read_dir})]
66
 
    if ReadDirFeature.available():
67
 
        adapter.scenarios.append(('pyrex',
68
 
            {'read_dir': ReadDirFeature.read_dir}))
69
 
    adapt_tests(to_adapt, adapter, result)
70
 
    return result
71
 
 
72
 
 
73
 
class _ReadDirFeature(Feature):
 
60
class _UTF8DirReaderFeature(Feature):
74
61
 
75
62
    def _probe(self):
76
63
        try:
77
64
            from bzrlib import _readdir_pyx
78
 
            self.read_dir = _readdir_pyx.read_dir
 
65
            self.reader = _readdir_pyx.UTF8DirReader
79
66
            return True
80
67
        except ImportError:
81
68
            return False
83
70
    def feature_name(self):
84
71
        return 'bzrlib._readdir_pyx'
85
72
 
86
 
ReadDirFeature = _ReadDirFeature()
 
73
UTF8DirReaderFeature = _UTF8DirReaderFeature()
87
74
 
88
75
 
89
76
class TestOSUtils(TestCaseInTempDir):
779
766
 
780
767
class TestWalkDirs(TestCaseInTempDir):
781
768
 
782
 
    def test_readdir(self):
783
 
        tree = [
784
 
            '.bzr/',
785
 
            '0file',
786
 
            '1dir/',
787
 
            '1dir/0file',
788
 
            '1dir/1dir/',
789
 
            '2file'
790
 
            ]
791
 
        self.build_tree(tree)
792
 
        expected_names = ['.bzr', '0file', '1dir', '2file']
793
 
        # read_dir returns pairs, which form a table with either None in all
794
 
        # the first columns, or a sort key to get best on-disk-read order, 
795
 
        # and the disk path name in utf-8 encoding in the second column.
796
 
        read_result = self.read_dir('.')
797
 
        # The second column is always the names, and every name except "." and
798
 
        # ".." should be present.
799
 
        names = sorted([row[1] for row in read_result])
800
 
        self.assertEqual(expected_names, names)
801
 
        expected_sort_key = None
802
 
        if read_result[0][0] is None:
803
 
            # No sort key returned - all keys must None
804
 
            operator = self.assertEqual
805
 
        else:
806
 
            # A sort key in the first row implies sort keys in the other rows.
807
 
            operator = self.assertNotEqual
808
 
        for row in read_result:
809
 
            operator(None, row[0])
810
 
 
811
 
    def test_compiled_extension_exists(self):
812
 
        self.requireFeature(ReadDirFeature)
813
 
        
814
769
    def test_walkdirs(self):
815
770
        tree = [
816
771
            '.bzr',
931
886
        self.assertIsInstance(osutils._selected_dir_reader, expected)
932
887
 
933
888
    def test_force_walkdirs_utf8_fs_utf8(self):
 
889
        self.requireFeature(UTF8DirReaderFeature)
934
890
        self._save_platform_info()
935
891
        win32utils.winver = None # Avoid the win32 detection code
936
892
        osutils._fs_enc = 'UTF-8'
937
 
        self.assertReadFSDirIs(osutils.UTF8DirReader)
 
893
        self.assertReadFSDirIs(UTF8DirReaderFeature.reader)
938
894
 
939
895
    def test_force_walkdirs_utf8_fs_ascii(self):
 
896
        self.requireFeature(UTF8DirReaderFeature)
940
897
        self._save_platform_info()
941
898
        win32utils.winver = None # Avoid the win32 detection code
942
899
        osutils._fs_enc = 'US-ASCII'
943
 
        self.assertReadFSDirIs(osutils.UTF8DirReader)
 
900
        self.assertReadFSDirIs(UTF8DirReaderFeature.reader)
944
901
 
945
902
    def test_force_walkdirs_utf8_fs_ANSI(self):
 
903
        self.requireFeature(UTF8DirReaderFeature)
946
904
        self._save_platform_info()
947
905
        win32utils.winver = None # Avoid the win32 detection code
948
906
        osutils._fs_enc = 'ANSI_X3.4-1968'
949
 
        self.assertReadFSDirIs(osutils.UTF8DirReader)
 
907
        self.assertReadFSDirIs(UTF8DirReaderFeature.reader)
950
908
 
951
909
    def test_force_walkdirs_utf8_fs_latin1(self):
952
910
        self._save_platform_info()