57
57
from bzrlib.tests.test__walkdirs_win32 import Win32ReadDirFeature
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)
73
class _ReadDirFeature(Feature):
60
class _UTF8DirReaderFeature(Feature):
77
64
from bzrlib import _readdir_pyx
78
self.read_dir = _readdir_pyx.read_dir
65
self.reader = _readdir_pyx.UTF8DirReader
80
67
except ImportError:
780
767
class TestWalkDirs(TestCaseInTempDir):
782
def test_readdir(self):
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
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])
811
def test_compiled_extension_exists(self):
812
self.requireFeature(ReadDirFeature)
814
769
def test_walkdirs(self):
931
886
self.assertIsInstance(osutils._selected_dir_reader, expected)
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)
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)
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)
951
909
def test_force_walkdirs_utf8_fs_latin1(self):
952
910
self._save_platform_info()