/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_win32utils.py

  • Committer: Jelmer Vernooij
  • Date: 2020-07-05 12:50:01 UTC
  • mfrom: (7490.40.46 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200705125001-7s3vo0p55szbbws7
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
315
315
        self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",
316
316
                               ["add", u"d/*"])
317
317
 
 
318
 
 
319
class TestGetEnvironUnicode(tests.TestCase):
 
320
    """Tests for accessing the environment via the windows wide api"""
 
321
 
 
322
    _test_needs_features = [features.win32_feature]
 
323
 
 
324
    def setUp(self):
 
325
        super(TestGetEnvironUnicode, self).setUp()
 
326
        self.overrideEnv("TEST", "1")
 
327
 
 
328
    def test_get(self):
 
329
        """In the normal case behaves the same as os.environ access"""
 
330
        self.assertEqual("1", win32utils.get_environ_unicode("TEST"))
 
331
 
 
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"))
 
336
 
 
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"))
 
341
 
 
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
 
345
        try:
 
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"))
 
351
 
 
352
    def test_long(self):
 
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"))
 
357
 
 
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
 
362
 
 
363
        def failer(*args, **kwargs):
 
364
            SetLastError(ERROR_INVALID_PARAMETER)
 
365
            return 0
 
366
        self.overrideAttr(win32utils.get_environ_unicode, "_c_function",
 
367
                          failer)
 
368
        e = self.assertRaises(WindowsError,
 
369
                              win32utils.get_environ_unicode, "TEST")
 
370
        self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER)