36
37
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
39
class _Win32RegistryFeature(Feature):
40
class _RequiredModuleFeature(Feature):
42
def __init__(self, mod_name):
43
self.mod_name = mod_name
44
super(_RequiredModuleFeature, self).__init__()
48
__import__(self.mod_name)
45
50
except ImportError:
48
53
def feature_name(self):
51
Win32RegistryFeature = _Win32RegistryFeature()
56
Win32RegistryFeature = _RequiredModuleFeature('_winreg')
57
CtypesFeature = _RequiredModuleFeature('ctypes')
58
Win32comShellFeature = _RequiredModuleFeature('win32com.shell')
160
167
def test_not_existing(self):
161
168
p = get_app_path('not-existing')
162
169
self.assertEquals('not-existing', p)
171
class TestLocationsCtypes(TestCase):
173
_test_needs_features = [CtypesFeature]
175
def test_appdata_not_using_environment(self):
176
# Test that we aren't falling back to the environment
177
first = bzrlib.win32utils.get_appdata_location()
178
old = os.environ.get("APPDATA")
180
del os.environ["APPDATA"]
182
self.assertEquals(first, bzrlib.win32utils.get_appdata_location())
185
os.environ["APPDATA"] = old
187
def test_appdata_matches_environment(self):
188
# Typically the APPDATA environment variable will match
189
# get_appdata_location
190
self.assertEquals(bzrlib.win32utils.get_appdata_location(),
191
os.environ["APPDATA"].decode(get_user_encoding()))
193
def test_local_appdata_not_using_environment(self):
194
# Test that we aren't falling back to the environment
195
first = bzrlib.win32utils.get_local_appdata_location()
196
old = os.environ.get("LOCALAPPDATA")
198
del os.environ["LOCALAPPDATA"]
200
self.assertEquals(first,
201
bzrlib.win32utils.get_local_appdata_location())
204
os.environ["LOCALAPPDATA"] = old
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.
209
lad = bzrlib.win32utils.get_local_appdata_location()
210
env = os.environ.get("LOCALAPPDATA")
212
self.assertEquals(lad, env)
214
class TestLocationsPywin32(TestCase):
216
_test_needs_features = [Win32comShellFeature]
219
self.old_ctypes = bzrlib.win32utils.has_ctypes
220
bzrlib.win32utils.has_ctypes = False
221
self.addCleanup(self.restoreCtypes)
223
def restoreCtypes(self):
224
bzrlib.win32utils.has_ctypes = self.old_ctypes
226
def test_appdata_not_using_environment(self):
227
# Test that we aren't falling back to the environment
228
first = bzrlib.win32utils.get_appdata_location()
229
old = os.environ.get("APPDATA")
231
del os.environ["APPDATA"]
233
self.assertEquals(first, bzrlib.win32utils.get_appdata_location())
236
os.environ["APPDATA"] = old
238
def test_appdata_matches_environment(self):
239
# Typically the APPDATA environment variable will match
240
# get_appdata_location
241
self.assertEquals(bzrlib.win32utils.get_appdata_location(),
242
os.environ["APPDATA"].decode(get_user_encoding()))
244
def test_local_appdata_not_using_environment(self):
245
# Test that we aren't falling back to the environment
246
first = bzrlib.win32utils.get_local_appdata_location()
247
old = os.environ.get("LOCALAPPDATA")
249
del os.environ["LOCALAPPDATA"]
251
self.assertEquals(first,
252
bzrlib.win32utils.get_local_appdata_location())
255
os.environ["LOCALAPPDATA"] = old
257
def test_local_appdata_matches_environment(self):
258
# LOCALAPPDATA typically only exists on Vista.
259
lad = bzrlib.win32utils.get_local_appdata_location()
260
env = os.environ.get("LOCALAPPDATA")
262
self.assertEquals(lad, env)