328
328
self.assertCommandLine([u"rm", u"x*"], "-m pdb rm x*", ["rm", u"x*"])
329
329
self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",
333
class TestGetEnvironUnicode(tests.TestCase):
334
"""Tests for accessing the environment via the windows wide api"""
336
_test_needs_features = [CtypesFeature, features.win32_feature]
339
super(TestGetEnvironUnicode, self).setUp()
340
self.overrideEnv("TEST", "1")
343
"""In the normal case behaves the same as os.environ access"""
344
self.assertEqual("1", win32utils.get_environ_unicode("TEST"))
346
def test_unset(self):
347
"""A variable not present in the environment gives None by default"""
348
del os.environ["TEST"]
349
self.assertIs(None, win32utils.get_environ_unicode("TEST"))
351
def test_unset_default(self):
352
"""A variable not present in the environment gives passed default"""
353
del os.environ["TEST"]
354
self.assertIs("a", win32utils.get_environ_unicode("TEST", "a"))
356
def test_unicode(self):
357
"""A non-ascii variable is returned as unicode"""
358
unicode_val = u"\xa7" # non-ascii character present in many encodings
360
bytes_val = unicode_val.encode(osutils.get_user_encoding())
361
except UnicodeEncodeError:
362
self.skip("Couldn't encode non-ascii string to place in environ")
363
os.environ["TEST"] = bytes_val
364
self.assertEqual(unicode_val, win32utils.get_environ_unicode("TEST"))
367
"""A variable bigger than heuristic buffer size is still accessible"""
368
big_val = "x" * (2<<10)
369
os.environ["TEST"] = big_val
370
self.assertEqual(big_val, win32utils.get_environ_unicode("TEST"))
372
def test_unexpected_error(self):
373
"""An error from the underlying platform function is propogated"""
374
ERROR_INVALID_PARAMETER = 87
375
SetLastError = win32utils.ctypes.windll.kernel32.SetLastError
376
def failer(*args, **kwargs):
377
SetLastError(ERROR_INVALID_PARAMETER)
379
self.overrideAttr(win32utils.get_environ_unicode, "_c_function",
381
e = self.assertRaises(WindowsError,
382
win32utils.get_environ_unicode, "TEST")
383
self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER)