/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: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
 
38
38
Win32RegistryFeature = features.ModuleAvailableFeature('_winreg')
39
 
 
 
39
CtypesFeature = features.ModuleAvailableFeature('ctypes')
 
40
Win32comShellFeature = features.ModuleAvailableFeature('win32com.shell')
 
41
Win32ApiFeature = features.ModuleAvailableFeature('win32api')
 
42
 
 
43
 
 
44
# Tests
 
45
# -----
40
46
 
41
47
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
42
48
 
181
187
        self.assertEqual('not-existing', p)
182
188
 
183
189
 
184
 
class TestLocations(TestCase):
 
190
class TestLocationsCtypes(TestCase):
185
191
 
186
 
    _test_needs_features = [features.win32_feature]
 
192
    _test_needs_features = [CtypesFeature, features.win32_feature]
187
193
 
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))
228
234
 
229
235
 
 
236
class TestLocationsPywin32(TestLocationsCtypes):
 
237
 
 
238
    _test_needs_features = [Win32comShellFeature]
 
239
 
 
240
    def setUp(self):
 
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
 
246
 
 
247
 
230
248
class TestSetHidden(TestCaseInTempDir):
231
249
 
232
 
    _test_needs_features = [features.win32_feature]
233
 
 
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/*",
316
332
                               ["add", u"d/*"])
317
333
 
 
334
 
 
335
class TestGetEnvironUnicode(tests.TestCase):
 
336
    """Tests for accessing the environment via the windows wide api"""
 
337
 
 
338
    _test_needs_features = [CtypesFeature, features.win32_feature]
 
339
 
 
340
    def setUp(self):
 
341
        super(TestGetEnvironUnicode, self).setUp()
 
342
        self.overrideEnv("TEST", "1")
 
343
 
 
344
    def test_get(self):
 
345
        """In the normal case behaves the same as os.environ access"""
 
346
        self.assertEqual("1", win32utils.get_environ_unicode("TEST"))
 
347
 
 
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"))
 
352
 
 
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"))
 
357
 
 
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
 
361
        try:
 
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"))
 
367
 
 
368
    def test_long(self):
 
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"))
 
373
 
 
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
 
378
 
 
379
        def failer(*args, **kwargs):
 
380
            SetLastError(ERROR_INVALID_PARAMETER)
 
381
            return 0
 
382
        self.overrideAttr(win32utils.get_environ_unicode, "_c_function",
 
383
                          failer)
 
384
        e = self.assertRaises(WindowsError,
 
385
                              win32utils.get_environ_unicode, "TEST")
 
386
        self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER)