/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 bzrlib/tests/test_win32utils.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-12 22:51:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4955.
  • Revision ID: john@arbash-meinel.com-20100112225131-he8h411p6aeeb947
Delay grabbing an output stream until we actually go to show a diff.

This makes the test suite happy, but it also seems to be reasonable.
If we aren't going to write anything, we don't need to hold an
output stream open.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
266
266
        super(TestLocationsPywin32, self).setUp()
267
267
        # We perform the exact same tests after disabling the use of ctypes.
268
268
        # This causes the implementation to fall back to pywin32.
269
 
        self.overrideAttr(win32utils, 'has_ctypes', False)
270
 
        # FIXME: this should be done by parametrization -- vila 100123
 
269
        self.old_ctypes = win32utils.has_ctypes
 
270
        win32utils.has_ctypes = False
 
271
        self.addCleanup(self.restoreCtypes)
 
272
 
 
273
    def restoreCtypes(self):
 
274
        win32utils.has_ctypes = self.old_ctypes
271
275
 
272
276
 
273
277
class TestSetHidden(TestCaseInTempDir):
288
292
 
289
293
 
290
294
 
 
295
class TestUnicodeShlex(tests.TestCase):
 
296
 
 
297
    def assertAsTokens(self, expected, line):
 
298
        s = win32utils.UnicodeShlex(line)
 
299
        self.assertEqual(expected, list(s))
 
300
 
 
301
    def test_simple(self):
 
302
        self.assertAsTokens([(False, u'foo'), (False, u'bar'), (False, u'baz')],
 
303
                            u'foo bar baz')
 
304
 
 
305
    def test_ignore_multiple_spaces(self):
 
306
        self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo  bar')
 
307
 
 
308
    def test_ignore_leading_space(self):
 
309
        self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'  foo bar')
 
310
 
 
311
    def test_ignore_trailing_space(self):
 
312
        self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar  ')
 
313
 
 
314
    def test_posix_quotations(self):
 
315
        self.assertAsTokens([(True, u'foo bar')], u'"foo bar"')
 
316
        self.assertAsTokens([(False, u"'fo''o"), (False, u"b''ar'")],
 
317
            u"'fo''o b''ar'")
 
318
        self.assertAsTokens([(True, u'foo bar')], u'"fo""o b""ar"')
 
319
        self.assertAsTokens([(True, u"fo'o"), (True, u"b'ar")],
 
320
            u'"fo"\'o b\'"ar"')
 
321
 
 
322
    def test_nested_quotations(self):
 
323
        self.assertAsTokens([(True, u'foo"" bar')], u"\"foo\\\"\\\" bar\"")
 
324
        self.assertAsTokens([(True, u'foo\'\' bar')], u"\"foo'' bar\"")
 
325
 
 
326
    def test_empty_result(self):
 
327
        self.assertAsTokens([], u'')
 
328
        self.assertAsTokens([], u'    ')
 
329
 
 
330
    def test_quoted_empty(self):
 
331
        self.assertAsTokens([(True, '')], u'""')
 
332
        self.assertAsTokens([(False, u"''")], u"''")
 
333
 
 
334
    def test_unicode_chars(self):
 
335
        self.assertAsTokens([(False, u'f\xb5\xee'), (False, u'\u1234\u3456')],
 
336
                             u'f\xb5\xee \u1234\u3456')
 
337
 
 
338
    def test_newline_in_quoted_section(self):
 
339
        self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u'"foo\nbar\nbaz\n"')
 
340
 
 
341
    def test_escape_chars(self):
 
342
        self.assertAsTokens([(False, u'foo\\bar')], u'foo\\bar')
 
343
 
 
344
    def test_escape_quote(self):
 
345
        self.assertAsTokens([(True, u'foo"bar')], u'"foo\\"bar"')
 
346
 
 
347
    def test_double_escape(self):
 
348
        self.assertAsTokens([(True, u'foo\\bar')], u'"foo\\\\bar"')
 
349
        self.assertAsTokens([(False, u'foo\\\\bar')], u"foo\\\\bar")
 
350
 
291
351
 
292
352
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
293
353
 
294
 
    def assertCommandLine(self, expected, line, single_quotes_allowed=False):
 
354
    def assertCommandLine(self, expected, line):
295
355
        # Strictly speaking we should respect parameter order versus glob
296
356
        # expansions, but it's not really worth the effort here
297
 
        argv = win32utils._command_line_to_argv(line,
298
 
                single_quotes_allowed=single_quotes_allowed)
299
 
        self.assertEqual(expected, sorted(argv))
 
357
        self.assertEqual(expected,
 
358
                         sorted(win32utils._command_line_to_argv(line)))
300
359
 
301
360
    def test_glob_paths(self):
302
361
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
312
371
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
313
372
        self.assertCommandLine([u'a/*.c'], '"a/*.c"')
314
373
        self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
315
 
        self.assertCommandLine([u'a/*.c'], "'a/*.c'",
316
 
            single_quotes_allowed=True)
317
374
 
318
375
    def test_slashes_changed(self):
319
376
        # Quoting doesn't change the supplied args
320
377
        self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
321
 
        self.assertCommandLine([u'a\\*.c'], "'a\\*.c'",
322
 
            single_quotes_allowed=True)
323
378
        # Expands the glob, but nothing matches, swaps slashes
324
379
        self.assertCommandLine([u'a/*.c'], 'a\\*.c')
325
380
        self.assertCommandLine([u'a/?.c'], 'a\\?.c')
326
381
        # No glob, doesn't touch slashes
327
382
        self.assertCommandLine([u'a\\foo.c'], 'a\\foo.c')
328
383
 
329
 
    def test_single_quote_support(self):
 
384
    def test_no_single_quote_supported(self):
330
385
        self.assertCommandLine(["add", "let's-do-it.txt"],
331
386
            "add let's-do-it.txt")
332
 
        self.assertCommandLine(["add", "lets do it.txt"],
333
 
            "add 'lets do it.txt'", single_quotes_allowed=True)
334
387
 
335
388
    def test_case_insensitive_globs(self):
336
389
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)