315
315
self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",
319
class TestGetEnvironUnicode(tests.TestCase):
320
"""Tests for accessing the environment via the windows wide api"""
322
_test_needs_features = [features.win32_feature]
325
super(TestGetEnvironUnicode, self).setUp()
326
self.overrideEnv("TEST", "1")
329
"""In the normal case behaves the same as os.environ access"""
330
self.assertEqual("1", win32utils.get_environ_unicode("TEST"))
332
def test_unset(self):
333
"""A variable not present in the environment gives None by default"""
334
del os.environ["TEST"]
335
self.assertIs(None, win32utils.get_environ_unicode("TEST"))
337
def test_unset_default(self):
338
"""A variable not present in the environment gives passed default"""
339
del os.environ["TEST"]
340
self.assertIs("a", win32utils.get_environ_unicode("TEST", "a"))
342
def test_unicode(self):
343
"""A non-ascii variable is returned as unicode"""
344
unicode_val = u"\xa7" # non-ascii character present in many encodings
346
bytes_val = unicode_val.encode(osutils.get_user_encoding())
347
except UnicodeEncodeError:
348
self.skipTest("Couldn't encode non-ascii string for environ")
349
os.environ["TEST"] = bytes_val
350
self.assertEqual(unicode_val, win32utils.get_environ_unicode("TEST"))
353
"""A variable bigger than heuristic buffer size is still accessible"""
354
big_val = "x" * (2 << 10)
355
os.environ["TEST"] = big_val
356
self.assertEqual(big_val, win32utils.get_environ_unicode("TEST"))
358
def test_unexpected_error(self):
359
"""An error from the underlying platform function is propogated"""
360
ERROR_INVALID_PARAMETER = 87
361
SetLastError = win32utils.ctypes.windll.kernel32.SetLastError
363
def failer(*args, **kwargs):
364
SetLastError(ERROR_INVALID_PARAMETER)
366
self.overrideAttr(win32utils.get_environ_unicode, "_c_function",
368
e = self.assertRaises(WindowsError,
369
win32utils.get_environ_unicode, "TEST")
370
self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER)