2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
1 |
# Copyright (C) 2007 Canonical Ltd
|
2617.5.1
by Kuno Meyer
Added direct unit tests for win32utils.glob_expand(). |
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
|
2617.5.1
by Kuno Meyer
Added direct unit tests for win32utils.glob_expand(). |
16 |
|
2681.4.2
by Alexander Belchenko
test for get_app_path |
17 |
import os |
2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
18 |
import sys |
19 |
||
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
20 |
from bzrlib import osutils |
4505.2.4
by Alexander Belchenko
guard tests with UnicodeFilenameFeature. |
21 |
from bzrlib.tests import ( |
22 |
Feature, |
|
23 |
TestCase, |
|
24 |
TestCaseInTempDir, |
|
25 |
TestSkipped, |
|
26 |
UnicodeFilenameFeature, |
|
27 |
)
|
|
2681.4.2
by Alexander Belchenko
test for get_app_path |
28 |
from bzrlib.win32utils import glob_expand, get_app_path |
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
29 |
from bzrlib import win32utils |
2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
30 |
|
31 |
||
32 |
# Features
|
|
33 |
# --------
|
|
34 |
||
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
35 |
class _NeedsGlobExpansionFeature(Feature): |
2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
36 |
|
37 |
def _probe(self): |
|
2617.5.5
by Kuno Meyer
Just a typo remained from testing. |
38 |
return sys.platform == 'win32' |
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
39 |
|
2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
40 |
def feature_name(self): |
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
41 |
return 'Internally performed glob expansion' |
2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
42 |
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
43 |
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature() |
2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
44 |
|
45 |
||
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
46 |
class _RequiredModuleFeature(Feature): |
47 |
||
48 |
def __init__(self, mod_name): |
|
49 |
self.mod_name = mod_name |
|
50 |
super(_RequiredModuleFeature, self).__init__() |
|
2681.4.4
by Alexander Belchenko
test use Feature instead of TestSkipped |
51 |
|
52 |
def _probe(self): |
|
53 |
try: |
|
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
54 |
__import__(self.mod_name) |
2681.4.4
by Alexander Belchenko
test use Feature instead of TestSkipped |
55 |
return True |
56 |
except ImportError: |
|
57 |
return False |
|
58 |
||
59 |
def feature_name(self): |
|
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
60 |
return self.mod_name |
2681.4.4
by Alexander Belchenko
test use Feature instead of TestSkipped |
61 |
|
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
62 |
Win32RegistryFeature = _RequiredModuleFeature('_winreg') |
63 |
CtypesFeature = _RequiredModuleFeature('ctypes') |
|
64 |
Win32comShellFeature = _RequiredModuleFeature('win32com.shell') |
|
2681.4.4
by Alexander Belchenko
test use Feature instead of TestSkipped |
65 |
|
66 |
||
2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
67 |
# Tests
|
68 |
# -----
|
|
2617.5.6
by Kuno Meyer
Incorporated feedback from the mailinglist. |
69 |
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
70 |
class TestNeedsGlobExpansionFeature(TestCase): |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
71 |
|
2617.5.6
by Kuno Meyer
Incorporated feedback from the mailinglist. |
72 |
def test_available(self): |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
73 |
self.assertEqual(sys.platform == 'win32', |
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
74 |
NeedsGlobExpansionFeature.available()) |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
75 |
|
2617.5.6
by Kuno Meyer
Incorporated feedback from the mailinglist. |
76 |
def test_str(self): |
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
77 |
self.assertTrue("performed" in str(NeedsGlobExpansionFeature)) |
2617.5.6
by Kuno Meyer
Incorporated feedback from the mailinglist. |
78 |
|
79 |
||
2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
80 |
class TestWin32UtilsGlobExpand(TestCaseInTempDir): |
2617.5.2
by Kuno Meyer
just reformatting |
81 |
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
82 |
_test_needs_features = [NeedsGlobExpansionFeature] |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
83 |
|
2617.5.1
by Kuno Meyer
Added direct unit tests for win32utils.glob_expand(). |
84 |
def test_empty_tree(self): |
85 |
self.build_tree([]) |
|
2617.5.2
by Kuno Meyer
just reformatting |
86 |
self._run_testset([ |
87 |
[['a'], ['a']], |
|
88 |
[['?'], ['?']], |
|
89 |
[['*'], ['*']], |
|
90 |
[['a', 'a'], ['a', 'a']]]) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
91 |
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
92 |
def test_tree_ascii(self): |
2617.5.7
by Kuno Meyer
Fix for non-ASCII filenames |
93 |
"""Checks the glob expansion and path separation char
|
94 |
normalization"""
|
|
2617.5.1
by Kuno Meyer
Added direct unit tests for win32utils.glob_expand(). |
95 |
self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1', |
96 |
'b', 'b1', 'b2', 'b3', |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
97 |
'c/', 'c/c1', 'c/c2', |
2617.5.4
by Kuno Meyer
Included feedback on initial patch. |
98 |
'd/', 'd/d1', 'd/d2', 'd/e/', 'd/e/e1']) |
2617.5.2
by Kuno Meyer
just reformatting |
99 |
self._run_testset([ |
100 |
# no wildcards
|
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
101 |
[[u'a'], [u'a']], |
102 |
[[u'a', u'a' ], [u'a', u'a']], |
|
103 |
[[u'A'], [u'A']], |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
104 |
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
105 |
[[u'd'], [u'd']], |
106 |
[[u'd/'], [u'd/']], |
|
107 |
[[u'd\\'], [u'd/']], |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
108 |
|
2617.5.2
by Kuno Meyer
just reformatting |
109 |
# wildcards
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
110 |
[[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']], |
111 |
[[u'?'], [u'a', u'b', u'c', u'd']], |
|
112 |
[[u'a?'], [u'a1', u'a2']], |
|
113 |
[[u'a??'], [u'a11', u'a.1']], |
|
114 |
[[u'b[1-2]'], [u'b1', u'b2']], |
|
115 |
[[u'A?'], [u'a1', u'a2']], |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
116 |
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
117 |
[[u'd/*'], [u'd/d1', u'd/d2', u'd/e']], |
118 |
[[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']], |
|
119 |
[[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']], |
|
120 |
[[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']], |
|
121 |
[[u'*/'], [u'c/', u'd/']], |
|
122 |
[[u'*\\'], [u'c/', u'd/']]]) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
123 |
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
124 |
def test_tree_unicode(self): |
2617.5.7
by Kuno Meyer
Fix for non-ASCII filenames |
125 |
"""Checks behaviour with non-ascii filenames"""
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
126 |
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235']) |
2617.5.7
by Kuno Meyer
Fix for non-ASCII filenames |
127 |
self._run_testset([ |
128 |
# no wildcards
|
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
129 |
[[u'\u1234'], [u'\u1234']], |
130 |
[[u'\u1235'], [u'\u1235']], |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
131 |
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
132 |
[[u'\u1235/'], [u'\u1235/']], |
133 |
[[u'\u1235/\u1235'], [u'\u1235/\u1235']], |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
134 |
|
2617.5.7
by Kuno Meyer
Fix for non-ASCII filenames |
135 |
# wildcards
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
136 |
[[u'?'], [u'\u1234', u'\u1235']], |
137 |
[[u'*'], [u'\u1234', u'\u1234\u1234', u'\u1235']], |
|
138 |
[[u'\u1234*'], [u'\u1234', u'\u1234\u1234']], |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
139 |
|
2617.5.8
by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range |
140 |
[[u'\u1235/?'], [u'\u1235/\u1235']], |
141 |
[[u'\u1235/*'], [u'\u1235/\u1235']], |
|
142 |
[[u'\u1235\\?'], [u'\u1235/\u1235']], |
|
143 |
[[u'\u1235\\*'], [u'\u1235/\u1235']], |
|
144 |
[[u'?/'], [u'\u1235/']], |
|
145 |
[[u'*/'], [u'\u1235/']], |
|
146 |
[[u'?\\'], [u'\u1235/']], |
|
147 |
[[u'*\\'], [u'\u1235/']], |
|
148 |
[[u'?/?'], [u'\u1235/\u1235']], |
|
149 |
[[u'*/*'], [u'\u1235/\u1235']], |
|
150 |
[[u'?\\?'], [u'\u1235/\u1235']], |
|
151 |
[[u'*\\*'], [u'\u1235/\u1235']]]) |
|
2617.5.7
by Kuno Meyer
Fix for non-ASCII filenames |
152 |
|
2617.5.1
by Kuno Meyer
Added direct unit tests for win32utils.glob_expand(). |
153 |
def _run_testset(self, testset): |
154 |
for pattern, expected in testset: |
|
155 |
result = glob_expand(pattern) |
|
156 |
expected.sort() |
|
157 |
result.sort() |
|
158 |
self.assertEqual(expected, result, 'pattern %s' % pattern) |
|
2617.5.2
by Kuno Meyer
just reformatting |
159 |
|
2681.4.2
by Alexander Belchenko
test for get_app_path |
160 |
|
161 |
class TestAppPaths(TestCase): |
|
162 |
||
2681.4.4
by Alexander Belchenko
test use Feature instead of TestSkipped |
163 |
_test_needs_features = [Win32RegistryFeature] |
164 |
||
2681.4.2
by Alexander Belchenko
test for get_app_path |
165 |
def test_iexplore(self): |
166 |
# typical windows users should have IE installed
|
|
167 |
for a in ('iexplore', 'iexplore.exe'): |
|
168 |
p = get_app_path(a) |
|
169 |
d, b = os.path.split(p) |
|
3146.4.9
by Aaron Bentley
do case-insensitive comparision of iexplore filename |
170 |
self.assertEquals('iexplore.exe', b.lower()) |
2681.4.2
by Alexander Belchenko
test for get_app_path |
171 |
self.assertNotEquals('', d) |
172 |
||
4476.2.1
by Alexander Belchenko
win32utils.py: get_app_path() can read path for wordpad.exe (data type_id is REG_EXPAND_SZ). |
173 |
def test_wordpad(self): |
174 |
# typical windows users should have wordpad in the system
|
|
175 |
# but there is problem: its path has the format REG_EXPAND_SZ
|
|
176 |
# so naive attempt to get the path is not working
|
|
177 |
for a in ('wordpad', 'wordpad.exe'): |
|
178 |
p = get_app_path(a) |
|
179 |
d, b = os.path.split(p) |
|
180 |
self.assertEquals('wordpad.exe', b.lower()) |
|
181 |
self.assertNotEquals('', d) |
|
182 |
||
2681.4.2
by Alexander Belchenko
test for get_app_path |
183 |
def test_not_existing(self): |
184 |
p = get_app_path('not-existing') |
|
185 |
self.assertEquals('not-existing', p) |
|
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
186 |
|
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
187 |
|
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
188 |
class TestLocationsCtypes(TestCase): |
189 |
||
190 |
_test_needs_features = [CtypesFeature] |
|
191 |
||
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
192 |
def assertPathsEqual(self, p1, p2): |
193 |
# TODO: The env var values in particular might return the "short"
|
|
194 |
# version (ie, "C:\DOCUME~1\..."). Its even possible the returned
|
|
195 |
# values will differ only by case - handle these situations as we
|
|
196 |
# come across them.
|
|
197 |
self.assertEquals(p1, p2) |
|
198 |
||
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
199 |
def test_appdata_not_using_environment(self): |
200 |
# Test that we aren't falling back to the environment
|
|
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
201 |
first = win32utils.get_appdata_location() |
202 |
self._captureVar("APPDATA", None) |
|
203 |
self.assertPathsEqual(first, win32utils.get_appdata_location()) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
204 |
|
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
205 |
def test_appdata_matches_environment(self): |
206 |
# Typically the APPDATA environment variable will match
|
|
207 |
# get_appdata_location
|
|
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
208 |
# XXX - See bug 262874, which asserts the correct encoding is 'mbcs',
|
209 |
encoding = osutils.get_user_encoding() |
|
3638.4.6
by Mark Hammond
Skip the environment checks when APPDATA isn't in the environment. |
210 |
env_val = os.environ.get("APPDATA", None) |
211 |
if not env_val: |
|
212 |
raise TestSkipped("No APPDATA environment variable exists") |
|
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
213 |
self.assertPathsEqual(win32utils.get_appdata_location(), |
3638.4.6
by Mark Hammond
Skip the environment checks when APPDATA isn't in the environment. |
214 |
env_val.decode(encoding)) |
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
215 |
|
216 |
def test_local_appdata_not_using_environment(self): |
|
217 |
# Test that we aren't falling back to the environment
|
|
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
218 |
first = win32utils.get_local_appdata_location() |
219 |
self._captureVar("LOCALAPPDATA", None) |
|
220 |
self.assertPathsEqual(first, win32utils.get_local_appdata_location()) |
|
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
221 |
|
222 |
def test_local_appdata_matches_environment(self): |
|
223 |
# LOCALAPPDATA typically only exists on Vista, so we only attempt to
|
|
224 |
# compare when it exists.
|
|
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
225 |
lad = win32utils.get_local_appdata_location() |
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
226 |
env = os.environ.get("LOCALAPPDATA") |
227 |
if env: |
|
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
228 |
# XXX - See bug 262874, which asserts the correct encoding is 'mbcs'
|
229 |
encoding = osutils.get_user_encoding() |
|
230 |
self.assertPathsEqual(lad, env.decode(encoding)) |
|
231 |
||
232 |
||
233 |
class TestLocationsPywin32(TestLocationsCtypes): |
|
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
234 |
|
235 |
_test_needs_features = [Win32comShellFeature] |
|
236 |
||
237 |
def setUp(self): |
|
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
238 |
super(TestLocationsPywin32, self).setUp() |
239 |
# We perform the exact same tests after disabling the use of ctypes.
|
|
240 |
# This causes the implementation to fall back to pywin32.
|
|
241 |
self.old_ctypes = win32utils.has_ctypes |
|
242 |
win32utils.has_ctypes = False |
|
3638.4.1
by Mark Hammond
Add win32utils.get_local_appdata_location() so bzr and plugins can |
243 |
self.addCleanup(self.restoreCtypes) |
244 |
||
245 |
def restoreCtypes(self): |
|
3638.4.3
by Mark Hammond
cleanup tests, rationalize path checking etc. |
246 |
win32utils.has_ctypes = self.old_ctypes |
4505.2.1
by Alexander Belchenko
Set hidden attribute on .bzr directory below unicode path should never fail with error. The operation should succeed even if bzr unable to set the attribute. (related to bug #335362). |
247 |
|
248 |
||
249 |
class TestSetHidden(TestCaseInTempDir): |
|
250 |
||
4505.2.3
by Alexander Belchenko
added direct test for absolute path. |
251 |
def test_unicode_dir(self): |
252 |
# we should handle unicode paths without errors
|
|
4505.2.4
by Alexander Belchenko
guard tests with UnicodeFilenameFeature. |
253 |
self.requireFeature(UnicodeFilenameFeature) |
4505.2.3
by Alexander Belchenko
added direct test for absolute path. |
254 |
os.mkdir(u'\u1234') |
255 |
win32utils.set_file_attr_hidden(u'\u1234') |
|
256 |
||
257 |
def test_dot_bzr_in_unicode_dir(self): |
|
4505.2.1
by Alexander Belchenko
Set hidden attribute on .bzr directory below unicode path should never fail with error. The operation should succeed even if bzr unable to set the attribute. (related to bug #335362). |
258 |
# we should not raise traceback if we try to set hidden attribute
|
259 |
# on .bzr directory below unicode path
|
|
4505.2.4
by Alexander Belchenko
guard tests with UnicodeFilenameFeature. |
260 |
self.requireFeature(UnicodeFilenameFeature) |
4505.2.3
by Alexander Belchenko
added direct test for absolute path. |
261 |
os.makedirs(u'\u1234\\.bzr') |
262 |
path = osutils.abspath(u'\u1234\\.bzr') |
|
263 |
win32utils.set_file_attr_hidden(path) |