/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: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

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