~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2008-09-11 19:36:38 UTC
  • mfrom: (3703 +trunk)
  • mto: (3705.1.1 trunk2)
  • mto: This revision was merged to the branch mainline in revision 3708.
  • Revision ID: v.ladeuil+lp@free.fr-20080911193638-wtjyc1kcmacc6t1f
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        pump_string_file,
41
41
        )
42
42
from bzrlib.tests import (
 
43
        adapt_tests,
 
44
        Feature,
43
45
        probe_unicode_in_user_encoding,
 
46
        split_suite_by_re,
44
47
        StringIOWrapper,
45
48
        SymlinkFeature,
46
49
        TestCase,
47
50
        TestCaseInTempDir,
 
51
        TestScenarioApplier,
48
52
        TestSkipped,
49
53
        )
50
54
from bzrlib.tests.file_utils import (
53
57
from bzrlib.tests.test__walkdirs_win32 import WalkdirsWin32Feature
54
58
 
55
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):
 
74
 
 
75
    def _probe(self):
 
76
        try:
 
77
            from bzrlib import _readdir_pyx
 
78
            self.read_dir = _readdir_pyx.read_dir
 
79
            return True
 
80
        except ImportError:
 
81
            return False
 
82
 
 
83
    def feature_name(self):
 
84
        return 'bzrlib._readdir_pyx'
 
85
 
 
86
ReadDirFeature = _ReadDirFeature()
 
87
 
 
88
 
56
89
class TestOSUtils(TestCaseInTempDir):
57
90
 
58
91
    def test_contains_whitespace(self):
746
779
 
747
780
class TestWalkDirs(TestCaseInTempDir):
748
781
 
 
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
        
749
814
    def test_walkdirs(self):
750
815
        tree = [
751
816
            '.bzr',