/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-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

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
    )
37
36
 
38
37
 
39
38
Win32RegistryFeature = features.ModuleAvailableFeature('_winreg')
40
 
CtypesFeature = features.ModuleAvailableFeature('ctypes')
41
 
Win32comShellFeature = features.ModuleAvailableFeature('win32com.shell')
42
 
Win32ApiFeature = features.ModuleAvailableFeature('win32api') 
43
 
 
44
 
 
45
 
# Tests
46
 
# -----
 
39
 
47
40
 
48
41
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
49
42
 
75
68
        self._run_testset([
76
69
            # no wildcards
77
70
            [[u'a'], [u'a']],
78
 
            [[u'a', u'a' ], [u'a', u'a']],
 
71
            [[u'a', u'a'], [u'a', u'a']],
79
72
 
80
73
            [[u'd'], [u'd']],
81
74
            [[u'd/'], [u'd/']],
188
181
        self.assertEqual('not-existing', p)
189
182
 
190
183
 
191
 
class TestLocationsCtypes(TestCase):
 
184
class TestLocations(TestCase):
192
185
 
193
 
    _test_needs_features = [CtypesFeature, features.win32_feature]
 
186
    _test_needs_features = [features.win32_feature]
194
187
 
195
188
    def assertPathsEqual(self, p1, p2):
196
189
        # TODO: The env var values in particular might return the "short"
228
221
        lad = win32utils.get_local_appdata_location()
229
222
        env = os.environ.get("LOCALAPPDATA")
230
223
        if env:
231
 
            # XXX - See bug 262874, which asserts the correct encoding is 'mbcs'
 
224
            # XXX - See bug 262874, which asserts the correct encoding is
 
225
            # 'mbcs'
232
226
            encoding = osutils.get_user_encoding()
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)
265
249
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
266
250
 
267
251
    def assertCommandLine(self, expected, line, argv=None,
268
 
            single_quotes_allowed=False):
 
252
                          single_quotes_allowed=False):
269
253
        # Strictly speaking we should respect parameter order versus glob
270
254
        # expansions, but it's not really worth the effort here
271
255
        if argv is None:
272
256
            argv = [line]
273
 
        argv = win32utils._command_line_to_argv(line, argv,
274
 
                single_quotes_allowed=single_quotes_allowed)
 
257
        argv = win32utils._command_line_to_argv(
 
258
            line, argv, single_quotes_allowed=single_quotes_allowed)
275
259
        self.assertEqual(expected, sorted(argv))
276
260
 
277
261
    def test_glob_paths(self):
289
273
        self.assertCommandLine([u'a/*.c'], '"a/*.c"')
290
274
        self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
291
275
        self.assertCommandLine([u'a/*.c'], "'a/*.c'",
292
 
            single_quotes_allowed=True)
 
276
                               single_quotes_allowed=True)
293
277
 
294
278
    def test_slashes_changed(self):
295
279
        # Quoting doesn't change the supplied args
296
280
        self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
297
281
        self.assertCommandLine([u'a\\*.c'], "'a\\*.c'",
298
 
            single_quotes_allowed=True)
 
282
                               single_quotes_allowed=True)
299
283
        # Expands the glob, but nothing matches, swaps slashes
300
284
        self.assertCommandLine([u'a/*.c'], 'a\\*.c')
301
285
        self.assertCommandLine([u'a/?.c'], 'a\\?.c')
304
288
 
305
289
    def test_single_quote_support(self):
306
290
        self.assertCommandLine(["add", "let's-do-it.txt"],
307
 
            "add let's-do-it.txt",
308
 
            ["add", "let's-do-it.txt"])
 
291
                               "add let's-do-it.txt",
 
292
                               ["add", "let's-do-it.txt"])
309
293
        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)
 
294
                           self.assertCommandLine, ["add", "lets do it.txt"],
 
295
                           "add 'lets do it.txt'", [
 
296
                               "add", "'lets", "do", "it.txt'"],
 
297
                           single_quotes_allowed=True)
313
298
 
314
299
    def test_case_insensitive_globs(self):
315
300
        if os.path.normcase("AbC") == "AbC":
328
313
        self.build_tree(['d/', 'd/f1', 'd/f2'])
329
314
        self.assertCommandLine([u"rm", u"x*"], "-m pdb rm x*", ["rm", u"x*"])
330
315
        self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",
331
 
            ["add", u"d/*"])
 
316
                               ["add", u"d/*"])
332
317
 
333
318
 
334
319
class TestGetEnvironUnicode(tests.TestCase):
335
320
    """Tests for accessing the environment via the windows wide api"""
336
321
 
337
 
    _test_needs_features = [CtypesFeature, features.win32_feature]
 
322
    _test_needs_features = [features.win32_feature]
338
323
 
339
324
    def setUp(self):
340
325
        super(TestGetEnvironUnicode, self).setUp()
356
341
 
357
342
    def test_unicode(self):
358
343
        """A non-ascii variable is returned as unicode"""
359
 
        unicode_val = u"\xa7" # non-ascii character present in many encodings
 
344
        unicode_val = u"\xa7"  # non-ascii character present in many encodings
360
345
        try:
361
346
            bytes_val = unicode_val.encode(osutils.get_user_encoding())
362
347
        except UnicodeEncodeError:
366
351
 
367
352
    def test_long(self):
368
353
        """A variable bigger than heuristic buffer size is still accessible"""
369
 
        big_val = "x" * (2<<10)
 
354
        big_val = "x" * (2 << 10)
370
355
        os.environ["TEST"] = big_val
371
356
        self.assertEqual(big_val, win32utils.get_environ_unicode("TEST"))
372
357
 
374
359
        """An error from the underlying platform function is propogated"""
375
360
        ERROR_INVALID_PARAMETER = 87
376
361
        SetLastError = win32utils.ctypes.windll.kernel32.SetLastError
 
362
 
377
363
        def failer(*args, **kwargs):
378
364
            SetLastError(ERROR_INVALID_PARAMETER)
379
365
            return 0
380
366
        self.overrideAttr(win32utils.get_environ_unicode, "_c_function",
381
 
            failer)
 
367
                          failer)
382
368
        e = self.assertRaises(WindowsError,
383
 
            win32utils.get_environ_unicode, "TEST")
 
369
                              win32utils.get_environ_unicode, "TEST")
384
370
        self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER)