40
40
_test_needs_features = [WalkdirsWin32Feature]
42
def assertWalkdirs(self, expected, top, prefix=''):
43
super(TestWin32Finder, self).setUp()
43
44
from bzrlib._walkdirs_win32 import (
44
_walkdirs_utf8_win32_find_file as walkdirs_utf8,
45
_walkdirs_utf8_win32_find_file
46
finder = walkdirs_utf8(top, prefix=prefix)
47
self.walkdirs_utf8 = _walkdirs_utf8_win32_find_file
49
def _remove_stat_from_dirblock(self, dirblock):
50
return [info[:3] + info[4:] for info in dirblock]
52
def assertWalkdirs(self, expected, top, prefix=''):
53
finder = self.walkdirs_utf8(top, prefix=prefix)
48
55
for dirname, dirblock in finder:
49
block_no_stat = [info[:3] + info[4:] for info in dirblock]
50
result.append((dirname, block_no_stat))
56
result.append((dirname, self._remove_stat_from_dirblock(dirblock)))
51
57
self.assertEqual(expected, result)
53
59
def test_empty_directory(self):
58
64
self.assertWalkdirs([
59
65
(('', u'.'), [('foo', 'foo', 'file', u'./foo')])
68
def test_subdir(self):
69
self.build_tree(['foo', 'bar/', 'bar/baz'])
71
(('', u'.'), [('bar', 'bar', 'directory', u'./bar'),
72
('foo', 'foo', 'file', u'./foo'),
74
(('bar', u'./bar'), [('bar/baz', 'baz', 'file', u'./bar/baz')]),
77
(('xxx', u'.'), [('xxx/bar', 'bar', 'directory', u'./bar'),
78
('xxx/foo', 'foo', 'file', u'./foo'),
80
(('xxx/bar', u'./bar'), [('xxx/bar/baz', 'baz', 'file', u'./bar/baz')]),
83
(('', u'bar'), [('baz', 'baz', 'file', u'bar/baz')]),
86
def test_skip_subdir(self):
87
self.build_tree(['a/', 'b/', 'c/', 'a/aa', 'b/bb', 'c/cc'])
88
base_dirblock = [('a', 'a', 'directory', u'./a'),
89
('b', 'b', 'directory', u'./b'),
90
('c', 'c', 'directory', u'./c'),
93
(('', u'.'), base_dirblock),
94
(('a', u'./a'), [('a/aa', 'aa', 'file', u'./a/aa')]),
95
(('b', u'./b'), [('b/bb', 'bb', 'file', u'./b/bb')]),
96
(('c', u'./c'), [('c/cc', 'cc', 'file', u'./c/cc')]),
99
walker = self.walkdirs_utf8('.')
100
dir_info, first_dirblock = walker.next()
101
self.assertEqual(('', u'.'), dir_info)
102
self.assertEqual(base_dirblock,
103
self._remove_stat_from_dirblock(first_dirblock))
104
# Now, remove 'b' and it should be skipped on the next round
105
del first_dirblock[1]
106
dir_info, second_dirblock = walker.next()
107
second_dirblock = self._remove_stat_from_dirblock(second_dirblock)
108
self.assertEqual(('a', u'./a'), dir_info)
109
self.assertEqual([('a/aa', 'aa', 'file', u'./a/aa')], second_dirblock)
110
dir_info, third_dirblock = walker.next()
111
third_dirblock = self._remove_stat_from_dirblock(third_dirblock)
112
self.assertEqual(('c', u'./c'), dir_info)
113
self.assertEqual([('c/cc', 'cc', 'file', u'./c/cc')], third_dirblock)