34
37
def feature_name(self):
35
return 'bzrlib._walkdirs_win32'
38
return 'bzrlib._Win32ReadDir'
37
WalkdirsWin32Feature = _WalkdirsWin32Feature()
40
Win32ReadDirFeature = _Win32ReadDirFeature()
40
43
class TestWin32Finder(tests.TestCaseInTempDir):
42
_test_needs_features = [WalkdirsWin32Feature]
45
_test_needs_features = [Win32ReadDirFeature]
45
48
super(TestWin32Finder, self).setUp()
46
49
from bzrlib._walkdirs_win32 import (
47
_walkdirs_utf8_win32_find_file
49
self.walkdirs_utf8 = _walkdirs_utf8_win32_find_file
52
self.reader = Win32ReadDir()
51
54
def _remove_stat_from_dirblock(self, dirblock):
52
55
return [info[:3] + info[4:] for info in dirblock]
54
57
def assertWalkdirs(self, expected, top, prefix=''):
55
finder = self.walkdirs_utf8(top, prefix=prefix)
57
for dirname, dirblock in finder:
58
result.append((dirname, self._remove_stat_from_dirblock(dirblock)))
58
old_selected_dir_reader = osutils._selected_dir_reader
60
osutils._selected_dir_reader = self.reader
61
finder = osutils._walkdirs_utf8(top, prefix=prefix)
63
for dirname, dirblock in finder:
64
dirblock = self._remove_stat_from_dirblock(dirblock)
65
result.append((dirname, dirblock))
66
self.assertEqual(expected, result)
68
osutils._selected_dir_reader = old_selected_dir_reader
70
def assertReadDir(self, expected, prefix, top_unicode):
71
result = self._remove_stat_from_dirblock(
72
self.reader.read_dir(prefix, top_unicode))
59
73
self.assertEqual(expected, result)
75
def test_top_prefix_to_starting_dir(self):
76
# preparing an iteration should create a unicode native path.
77
self.assertEqual(('prefix', None, None, None, u'\x12'),
78
self.reader.top_prefix_to_starting_dir(u'\x12'.encode('utf8'),
61
81
def test_empty_directory(self):
82
self.assertReadDir([], 'prefix', u'.')
62
83
self.assertWalkdirs([(('', u'.'), [])], u'.')
64
def test_file_in_dir(self):
65
86
self.build_tree(['foo'])
67
(('', u'.'), [('foo', 'foo', 'file', u'./foo')])
70
def test_subdir(self):
71
self.build_tree(['foo', 'bar/', 'bar/baz'])
73
(('', u'.'), [('bar', 'bar', 'directory', u'./bar'),
74
('foo', 'foo', 'file', u'./foo'),
76
(('bar', u'./bar'), [('bar/baz', 'baz', 'file', u'./bar/baz')]),
79
(('xxx', u'.'), [('xxx/bar', 'bar', 'directory', u'./bar'),
80
('xxx/foo', 'foo', 'file', u'./foo'),
82
(('xxx/bar', u'./bar'), [('xxx/bar/baz', 'baz', 'file', u'./bar/baz')]),
85
(('', u'bar'), [('baz', 'baz', 'file', u'bar/baz')]),
88
def test_skip_subdir(self):
89
self.build_tree(['a/', 'b/', 'c/', 'a/aa', 'b/bb', 'c/cc'])
90
base_dirblock = [('a', 'a', 'directory', u'./a'),
91
('b', 'b', 'directory', u'./b'),
92
('c', 'c', 'directory', u'./c'),
95
(('', u'.'), base_dirblock),
96
(('a', u'./a'), [('a/aa', 'aa', 'file', u'./a/aa')]),
97
(('b', u'./b'), [('b/bb', 'bb', 'file', u'./b/bb')]),
98
(('c', u'./c'), [('c/cc', 'cc', 'file', u'./c/cc')]),
101
walker = self.walkdirs_utf8('.')
102
dir_info, first_dirblock = walker.next()
103
self.assertEqual(('', u'.'), dir_info)
104
self.assertEqual(base_dirblock,
105
self._remove_stat_from_dirblock(first_dirblock))
106
# Now, remove 'b' and it should be skipped on the next round
107
del first_dirblock[1]
108
dir_info, second_dirblock = walker.next()
109
second_dirblock = self._remove_stat_from_dirblock(second_dirblock)
110
self.assertEqual(('a', u'./a'), dir_info)
111
self.assertEqual([('a/aa', 'aa', 'file', u'./a/aa')], second_dirblock)
112
dir_info, third_dirblock = walker.next()
113
third_dirblock = self._remove_stat_from_dirblock(third_dirblock)
114
self.assertEqual(('c', u'./c'), dir_info)
115
self.assertEqual([('c/cc', 'cc', 'file', u'./c/cc')], third_dirblock)
87
self.assertReadDir([('foo', 'foo', 'file', u'./foo')],
91
self.build_tree(['bar/'])
92
self.assertReadDir([('bar', 'bar', 'directory', u'./bar')],
95
def test_prefix(self):
96
self.build_tree(['bar/', 'baf'])
98
('xxx/baf', 'baf', 'file', u'./baf'),
99
('xxx/bar', 'bar', 'directory', u'./bar'),
117
103
def test_missing_dir(self):
118
e = self.assertRaises(WindowsError, list,
119
self.walkdirs_utf8(u'no_such_dir'))
104
e = self.assertRaises(WindowsError,
105
self.reader.read_dir, 'prefix', u'no_such_dir')
120
106
self.assertEqual(errno.ENOENT, e.errno)
121
107
self.assertEqual(3, e.winerror)
122
108
self.assertEqual((3, u'no_such_dir/*'), e.args)