bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
|
3504.4.3
by John Arbash Meinel
Start working on an extension specifically for win32, |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
3504.4.3
by John Arbash Meinel
Start working on an extension specifically for win32, |
16 |
|
17 |
"""Tests for the win32 walkdir extension."""
|
|
18 |
||
3504.4.8
by John Arbash Meinel
Some code cleanups. |
19 |
import errno |
20 |
||
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
21 |
from .. import ( |
3696.3.2
by John Arbash Meinel
Fix up some of the path joining logic. |
22 |
osutils, |
23 |
tests, |
|
24 |
)
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
25 |
from . import ( |
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
26 |
features, |
27 |
)
|
|
28 |
||
29 |
||
7143.15.2
by Jelmer Vernooij
Run autopep8. |
30 |
win32_readdir_feature = features.ModuleAvailableFeature( |
31 |
'breezy._walkdirs_win32') |
|
3504.4.3
by John Arbash Meinel
Start working on an extension specifically for win32, |
32 |
|
33 |
||
34 |
class TestWin32Finder(tests.TestCaseInTempDir): |
|
35 |
||
4913.2.6
by John Arbash Meinel
Switch Win32ReadDirFeature, which was probing for the wrong module anyway... :) |
36 |
_test_needs_features = [win32_readdir_feature] |
3504.4.3
by John Arbash Meinel
Start working on an extension specifically for win32, |
37 |
|
3504.4.5
by John Arbash Meinel
Add tests to ensure that you can skip subdirs, start exposing the function. |
38 |
def setUp(self): |
39 |
super(TestWin32Finder, self).setUp() |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
40 |
from ._walkdirs_win32 import ( |
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
41 |
Win32ReadDir, |
3504.4.3
by John Arbash Meinel
Start working on an extension specifically for win32, |
42 |
)
|
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
43 |
self.reader = Win32ReadDir() |
3504.4.5
by John Arbash Meinel
Add tests to ensure that you can skip subdirs, start exposing the function. |
44 |
|
45 |
def _remove_stat_from_dirblock(self, dirblock): |
|
46 |
return [info[:3] + info[4:] for info in dirblock] |
|
47 |
||
48 |
def assertWalkdirs(self, expected, top, prefix=''): |
|
3696.3.2
by John Arbash Meinel
Fix up some of the path joining logic. |
49 |
old_selected_dir_reader = osutils._selected_dir_reader |
50 |
try: |
|
51 |
osutils._selected_dir_reader = self.reader |
|
52 |
finder = osutils._walkdirs_utf8(top, prefix=prefix) |
|
53 |
result = [] |
|
54 |
for dirname, dirblock in finder: |
|
55 |
dirblock = self._remove_stat_from_dirblock(dirblock) |
|
56 |
result.append((dirname, dirblock)) |
|
57 |
self.assertEqual(expected, result) |
|
58 |
finally: |
|
59 |
osutils._selected_dir_reader = old_selected_dir_reader |
|
3504.4.3
by John Arbash Meinel
Start working on an extension specifically for win32, |
60 |
|
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
61 |
def assertReadDir(self, expected, prefix, top_unicode): |
62 |
result = self._remove_stat_from_dirblock( |
|
63 |
self.reader.read_dir(prefix, top_unicode)) |
|
64 |
self.assertEqual(expected, result) |
|
65 |
||
66 |
def test_top_prefix_to_starting_dir(self): |
|
67 |
# preparing an iteration should create a unicode native path.
|
|
7143.15.5
by Jelmer Vernooij
More PEP8 fixes. |
68 |
self.assertEqual( |
69 |
('prefix', None, None, None, u'\x12'), |
|
70 |
self.reader.top_prefix_to_starting_dir( |
|
71 |
u'\x12'.encode('utf8'), 'prefix')) |
|
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
72 |
|
3504.4.3
by John Arbash Meinel
Start working on an extension specifically for win32, |
73 |
def test_empty_directory(self): |
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
74 |
self.assertReadDir([], 'prefix', u'.') |
3504.4.3
by John Arbash Meinel
Start working on an extension specifically for win32, |
75 |
self.assertWalkdirs([(('', u'.'), [])], u'.') |
3504.4.4
by John Arbash Meinel
We have walkdirs basically working, only without timestamps |
76 |
|
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
77 |
def test_file(self): |
3504.4.4
by John Arbash Meinel
We have walkdirs basically working, only without timestamps |
78 |
self.build_tree(['foo']) |
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
79 |
self.assertReadDir([('foo', 'foo', 'file', u'./foo')], |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
80 |
'', u'.') |
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
81 |
|
5235.2.1
by Martin
Rename test method in bt.test__walkdirs_win32 that clashes with an attribute name |
82 |
def test_directory(self): |
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
83 |
self.build_tree(['bar/']) |
84 |
self.assertReadDir([('bar', 'bar', 'directory', u'./bar')], |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
85 |
'', u'.') |
3696.3.1
by Robert Collins
Refactor bzrlib.osutils._walkdirs_utf8 to aid API migration in future. |
86 |
|
87 |
def test_prefix(self): |
|
88 |
self.build_tree(['bar/', 'baf']) |
|
89 |
self.assertReadDir([ |
|
90 |
('xxx/baf', 'baf', 'file', u'./baf'), |
|
91 |
('xxx/bar', 'bar', 'directory', u'./bar'), |
|
92 |
],
|
|
93 |
'xxx', u'.') |
|
3504.4.8
by John Arbash Meinel
Some code cleanups. |
94 |
|
95 |
def test_missing_dir(self): |
|
3696.3.3
by John Arbash Meinel
read_dir raises the exception directly, it isn't an iterator/generator |
96 |
e = self.assertRaises(WindowsError, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
97 |
self.reader.read_dir, 'prefix', u'no_such_dir') |
3504.4.8
by John Arbash Meinel
Some code cleanups. |
98 |
self.assertEqual(errno.ENOENT, e.errno) |
99 |
self.assertEqual(3, e.winerror) |
|
100 |
self.assertEqual((3, u'no_such_dir/*'), e.args) |
|
6015.56.3
by Alexander Belchenko
added test to check that st_dev, st_ino, st_uid, st_gid are actually present in _Win32Stat object and have predefined (zero) value. |
101 |
|
102 |
||
103 |
class Test_Win32Stat(tests.TestCaseInTempDir): |
|
104 |
||
105 |
_test_needs_features = [win32_readdir_feature] |
|
106 |
||
107 |
def setUp(self): |
|
108 |
super(Test_Win32Stat, self).setUp() |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
109 |
from ._walkdirs_win32 import lstat |
6015.56.3
by Alexander Belchenko
added test to check that st_dev, st_ino, st_uid, st_gid are actually present in _Win32Stat object and have predefined (zero) value. |
110 |
self.win32_lstat = lstat |
111 |
||
112 |
def test_zero_members_present(self): |
|
113 |
self.build_tree(['foo']) |
|
114 |
st = self.win32_lstat('foo') |
|
115 |
# we only want to ensure that some members are present
|
|
116 |
self.assertEqual(0, st.st_dev) |
|
117 |
self.assertEqual(0, st.st_ino) |
|
118 |
self.assertEqual(0, st.st_uid) |
|
119 |
self.assertEqual(0, st.st_gid) |