/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
 
38
38
Win32RegistryFeature = features.ModuleAvailableFeature('_winreg')
39
 
CtypesFeature = features.ModuleAvailableFeature('ctypes')
40
 
Win32comShellFeature = features.ModuleAvailableFeature('win32com.shell')
41
 
Win32ApiFeature = features.ModuleAvailableFeature('win32api')
42
 
 
43
 
 
44
 
# Tests
45
 
# -----
 
39
 
46
40
 
47
41
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
48
42
 
187
181
        self.assertEqual('not-existing', p)
188
182
 
189
183
 
190
 
class TestLocationsCtypes(TestCase):
 
184
class TestLocations(TestCase):
191
185
 
192
 
    _test_needs_features = [CtypesFeature, features.win32_feature]
 
186
    _test_needs_features = [features.win32_feature]
193
187
 
194
188
    def assertPathsEqual(self, p1, p2):
195
189
        # TODO: The env var values in particular might return the "short"
233
227
            self.assertPathsEqual(lad, env.decode(encoding))
234
228
 
235
229
 
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
 
 
248
230
class TestSetHidden(TestCaseInTempDir):
249
231
 
 
232
    _test_needs_features = [features.win32_feature]
 
233
 
250
234
    def test_unicode_dir(self):
251
235
        # we should handle unicode paths without errors
252
236
        self.requireFeature(features.UnicodeFilenameFeature)
331
315
        self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",
332
316
                               ["add", u"d/*"])
333
317
 
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)