/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-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from .. import (
22
22
    osutils,
23
 
    symbol_versioning,
24
23
    tests,
25
24
    win32utils,
26
25
    )
39
38
Win32RegistryFeature = features.ModuleAvailableFeature('_winreg')
40
39
CtypesFeature = features.ModuleAvailableFeature('ctypes')
41
40
Win32comShellFeature = features.ModuleAvailableFeature('win32com.shell')
42
 
Win32ApiFeature = features.ModuleAvailableFeature('win32api') 
 
41
Win32ApiFeature = features.ModuleAvailableFeature('win32api')
43
42
 
44
43
 
45
44
# Tests
75
74
        self._run_testset([
76
75
            # no wildcards
77
76
            [[u'a'], [u'a']],
78
 
            [[u'a', u'a' ], [u'a', u'a']],
 
77
            [[u'a', u'a'], [u'a', u'a']],
79
78
 
80
79
            [[u'd'], [u'd']],
81
80
            [[u'd/'], [u'd/']],
228
227
        lad = win32utils.get_local_appdata_location()
229
228
        env = os.environ.get("LOCALAPPDATA")
230
229
        if env:
231
 
            # XXX - See bug 262874, which asserts the correct encoding is 'mbcs'
 
230
            # XXX - See bug 262874, which asserts the correct encoding is
 
231
            # 'mbcs'
232
232
            encoding = osutils.get_user_encoding()
233
233
            self.assertPathsEqual(lad, env.decode(encoding))
234
234
 
265
265
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
266
266
 
267
267
    def assertCommandLine(self, expected, line, argv=None,
268
 
            single_quotes_allowed=False):
 
268
                          single_quotes_allowed=False):
269
269
        # Strictly speaking we should respect parameter order versus glob
270
270
        # expansions, but it's not really worth the effort here
271
271
        if argv is None:
272
272
            argv = [line]
273
 
        argv = win32utils._command_line_to_argv(line, argv,
274
 
                single_quotes_allowed=single_quotes_allowed)
 
273
        argv = win32utils._command_line_to_argv(
 
274
            line, argv, single_quotes_allowed=single_quotes_allowed)
275
275
        self.assertEqual(expected, sorted(argv))
276
276
 
277
277
    def test_glob_paths(self):
289
289
        self.assertCommandLine([u'a/*.c'], '"a/*.c"')
290
290
        self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
291
291
        self.assertCommandLine([u'a/*.c'], "'a/*.c'",
292
 
            single_quotes_allowed=True)
 
292
                               single_quotes_allowed=True)
293
293
 
294
294
    def test_slashes_changed(self):
295
295
        # Quoting doesn't change the supplied args
296
296
        self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
297
297
        self.assertCommandLine([u'a\\*.c'], "'a\\*.c'",
298
 
            single_quotes_allowed=True)
 
298
                               single_quotes_allowed=True)
299
299
        # Expands the glob, but nothing matches, swaps slashes
300
300
        self.assertCommandLine([u'a/*.c'], 'a\\*.c')
301
301
        self.assertCommandLine([u'a/?.c'], 'a\\?.c')
304
304
 
305
305
    def test_single_quote_support(self):
306
306
        self.assertCommandLine(["add", "let's-do-it.txt"],
307
 
            "add let's-do-it.txt",
308
 
            ["add", "let's-do-it.txt"])
 
307
                               "add let's-do-it.txt",
 
308
                               ["add", "let's-do-it.txt"])
309
309
        self.expectFailure("Using single quotes breaks trimming from argv",
310
 
            self.assertCommandLine, ["add", "lets do it.txt"],
311
 
            "add 'lets do it.txt'", ["add", "'lets", "do", "it.txt'"],
312
 
            single_quotes_allowed=True)
 
310
                           self.assertCommandLine, ["add", "lets do it.txt"],
 
311
                           "add 'lets do it.txt'", [
 
312
                               "add", "'lets", "do", "it.txt'"],
 
313
                           single_quotes_allowed=True)
313
314
 
314
315
    def test_case_insensitive_globs(self):
315
316
        if os.path.normcase("AbC") == "AbC":
328
329
        self.build_tree(['d/', 'd/f1', 'd/f2'])
329
330
        self.assertCommandLine([u"rm", u"x*"], "-m pdb rm x*", ["rm", u"x*"])
330
331
        self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",
331
 
            ["add", u"d/*"])
 
332
                               ["add", u"d/*"])
332
333
 
333
334
 
334
335
class TestGetEnvironUnicode(tests.TestCase):
356
357
 
357
358
    def test_unicode(self):
358
359
        """A non-ascii variable is returned as unicode"""
359
 
        unicode_val = u"\xa7" # non-ascii character present in many encodings
 
360
        unicode_val = u"\xa7"  # non-ascii character present in many encodings
360
361
        try:
361
362
            bytes_val = unicode_val.encode(osutils.get_user_encoding())
362
363
        except UnicodeEncodeError:
366
367
 
367
368
    def test_long(self):
368
369
        """A variable bigger than heuristic buffer size is still accessible"""
369
 
        big_val = "x" * (2<<10)
 
370
        big_val = "x" * (2 << 10)
370
371
        os.environ["TEST"] = big_val
371
372
        self.assertEqual(big_val, win32utils.get_environ_unicode("TEST"))
372
373
 
374
375
        """An error from the underlying platform function is propogated"""
375
376
        ERROR_INVALID_PARAMETER = 87
376
377
        SetLastError = win32utils.ctypes.windll.kernel32.SetLastError
 
378
 
377
379
        def failer(*args, **kwargs):
378
380
            SetLastError(ERROR_INVALID_PARAMETER)
379
381
            return 0
380
382
        self.overrideAttr(win32utils.get_environ_unicode, "_c_function",
381
 
            failer)
 
383
                          failer)
382
384
        e = self.assertRaises(WindowsError,
383
 
            win32utils.get_environ_unicode, "TEST")
 
385
                              win32utils.get_environ_unicode, "TEST")
384
386
        self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER)