276
291
win32utils.set_file_attr_hidden(path)
295
class TestUnicodeShlex(tests.TestCase):
297
def assertAsTokens(self, expected, line):
298
s = win32utils.UnicodeShlex(line)
299
self.assertEqual(expected, list(s))
301
def test_simple(self):
302
self.assertAsTokens([(False, u'foo'), (False, u'bar'), (False, u'baz')],
305
def test_ignore_multiple_spaces(self):
306
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar')
308
def test_ignore_leading_space(self):
309
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u' foo bar')
311
def test_ignore_trailing_space(self):
312
self.assertAsTokens([(False, u'foo'), (False, u'bar')], u'foo bar ')
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'")],
318
self.assertAsTokens([(True, u'foo bar')], u'"fo""o b""ar"')
319
self.assertAsTokens([(True, u"fo'o"), (True, u"b'ar")],
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\"")
326
def test_empty_result(self):
327
self.assertAsTokens([], u'')
328
self.assertAsTokens([], u' ')
330
def test_quoted_empty(self):
331
self.assertAsTokens([(True, '')], u'""')
332
self.assertAsTokens([(False, u"''")], u"''")
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')
338
def test_newline_in_quoted_section(self):
339
self.assertAsTokens([(True, u'foo\nbar\nbaz\n')], u'"foo\nbar\nbaz\n"')
341
def test_escape_chars(self):
342
self.assertAsTokens([(False, u'foo\\bar')], u'foo\\bar')
344
def test_escape_quote(self):
345
self.assertAsTokens([(True, u'foo"bar')], u'"foo\\"bar"')
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")
279
352
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
281
def assertCommandLine(self, expected, line, argv=None,
282
single_quotes_allowed=False):
354
def assertCommandLine(self, expected, line):
283
355
# Strictly speaking we should respect parameter order versus glob
284
356
# expansions, but it's not really worth the effort here
287
argv = win32utils._command_line_to_argv(line, argv,
288
single_quotes_allowed=single_quotes_allowed)
289
self.assertEqual(expected, sorted(argv))
357
self.assertEqual(expected,
358
sorted(win32utils._command_line_to_argv(line)))
291
360
def test_glob_paths(self):
292
361
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
302
371
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
303
372
self.assertCommandLine([u'a/*.c'], '"a/*.c"')
304
373
self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
305
self.assertCommandLine([u'a/*.c'], "'a/*.c'",
306
single_quotes_allowed=True)
308
375
def test_slashes_changed(self):
309
376
# Quoting doesn't change the supplied args
310
377
self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
311
self.assertCommandLine([u'a\\*.c'], "'a\\*.c'",
312
single_quotes_allowed=True)
313
378
# Expands the glob, but nothing matches, swaps slashes
314
379
self.assertCommandLine([u'a/*.c'], 'a\\*.c')
315
380
self.assertCommandLine([u'a/?.c'], 'a\\?.c')
316
381
# No glob, doesn't touch slashes
317
382
self.assertCommandLine([u'a\\foo.c'], 'a\\foo.c')
319
def test_single_quote_support(self):
384
def test_no_single_quote_supported(self):
320
385
self.assertCommandLine(["add", "let's-do-it.txt"],
321
"add let's-do-it.txt",
322
["add", "let's-do-it.txt"])
323
self.expectFailure("Using single quotes breaks trimming from argv",
324
self.assertCommandLine, ["add", "lets do it.txt"],
325
"add 'lets do it.txt'", ["add", "'lets", "do", "it.txt'"],
326
single_quotes_allowed=True)
386
"add let's-do-it.txt")
328
388
def test_case_insensitive_globs(self):
329
389
self.requireFeature(tests.CaseInsCasePresFilenameFeature)
331
391
self.assertCommandLine([u'A/b.c'], 'A/B*')
333
393
def test_backslashes(self):
334
self.requireFeature(backslashdir_feature)
394
self.requireFeature(BackslashDirSeparatorFeature)
335
395
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
336
396
self.assertCommandLine([u'a/b.c'], 'a\\b*')
338
def test_with_pdb(self):
339
"""Check stripping Python arguments before bzr script per lp:587868"""
340
self.assertCommandLine([u"rocks"], "-m pdb rocks", ["rocks"])
341
self.build_tree(['d/', 'd/f1', 'd/f2'])
342
self.assertCommandLine([u"rm", u"x*"], "-m pdb rm x*", ["rm", u"x*"])
343
self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",