38
38
Win32RegistryFeature = features.ModuleAvailableFeature('_winreg')
39
CtypesFeature = features.ModuleAvailableFeature('ctypes')
40
Win32comShellFeature = features.ModuleAvailableFeature('win32com.shell')
41
Win32ApiFeature = features.ModuleAvailableFeature('win32api')
41
47
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
181
187
self.assertEqual('not-existing', p)
184
class TestLocations(TestCase):
190
class TestLocationsCtypes(TestCase):
186
_test_needs_features = [features.win32_feature]
192
_test_needs_features = [CtypesFeature, features.win32_feature]
188
194
def assertPathsEqual(self, p1, p2):
189
195
# TODO: The env var values in particular might return the "short"
227
233
self.assertPathsEqual(lad, env.decode(encoding))
236
class TestLocationsPywin32(TestLocationsCtypes):
238
_test_needs_features = [Win32comShellFeature]
241
super(TestLocationsPywin32, self).setUp()
242
# We perform the exact same tests after disabling the use of ctypes.
243
# This causes the implementation to fall back to pywin32.
244
self.overrideAttr(win32utils, 'has_ctypes', False)
245
# FIXME: this should be done by parametrization -- vila 100123
230
248
class TestSetHidden(TestCaseInTempDir):
232
_test_needs_features = [features.win32_feature]
234
250
def test_unicode_dir(self):
235
251
# we should handle unicode paths without errors
236
252
self.requireFeature(features.UnicodeFilenameFeature)
315
331
self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",
335
class TestGetEnvironUnicode(tests.TestCase):
336
"""Tests for accessing the environment via the windows wide api"""
338
_test_needs_features = [CtypesFeature, features.win32_feature]
341
super(TestGetEnvironUnicode, self).setUp()
342
self.overrideEnv("TEST", "1")
345
"""In the normal case behaves the same as os.environ access"""
346
self.assertEqual("1", win32utils.get_environ_unicode("TEST"))
348
def test_unset(self):
349
"""A variable not present in the environment gives None by default"""
350
del os.environ["TEST"]
351
self.assertIs(None, win32utils.get_environ_unicode("TEST"))
353
def test_unset_default(self):
354
"""A variable not present in the environment gives passed default"""
355
del os.environ["TEST"]
356
self.assertIs("a", win32utils.get_environ_unicode("TEST", "a"))
358
def test_unicode(self):
359
"""A non-ascii variable is returned as unicode"""
360
unicode_val = u"\xa7" # non-ascii character present in many encodings
362
bytes_val = unicode_val.encode(osutils.get_user_encoding())
363
except UnicodeEncodeError:
364
self.skipTest("Couldn't encode non-ascii string for environ")
365
os.environ["TEST"] = bytes_val
366
self.assertEqual(unicode_val, win32utils.get_environ_unicode("TEST"))
369
"""A variable bigger than heuristic buffer size is still accessible"""
370
big_val = "x" * (2 << 10)
371
os.environ["TEST"] = big_val
372
self.assertEqual(big_val, win32utils.get_environ_unicode("TEST"))
374
def test_unexpected_error(self):
375
"""An error from the underlying platform function is propogated"""
376
ERROR_INVALID_PARAMETER = 87
377
SetLastError = win32utils.ctypes.windll.kernel32.SetLastError
379
def failer(*args, **kwargs):
380
SetLastError(ERROR_INVALID_PARAMETER)
382
self.overrideAttr(win32utils.get_environ_unicode, "_c_function",
384
e = self.assertRaises(WindowsError,
385
win32utils.get_environ_unicode, "TEST")
386
self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER)