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