20
from bzrlib import osutils
21
from bzrlib.tests import TestCase, TestCaseInTempDir, TestSkipped, Feature
25
from bzrlib.tests import (
30
UnicodeFilenameFeature,
22
32
from bzrlib.win32utils import glob_expand, get_app_path
23
from bzrlib import win32utils
29
class _NeedsGlobExpansionFeature(Feature):
35
class _BackslashDirSeparatorFeature(tests.Feature):
32
return sys.platform == 'win32'
39
os.lstat(os.getcwd() + '\\')
34
45
def feature_name(self):
35
return 'Internally performed glob expansion'
46
return "Filesystem treats '\\' as a directory separator."
37
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
48
BackslashDirSeparatorFeature = _BackslashDirSeparatorFeature()
40
51
class _RequiredModuleFeature(Feature):
84
85
[['a', 'a'], ['a', 'a']]])
86
def test_tree_ascii(self):
87
"""Checks the glob expansion and path separation char
87
def build_ascii_tree(self):
89
88
self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
90
89
'b', 'b1', 'b2', 'b3',
91
90
'c/', 'c/c1', 'c/c2',
92
91
'd/', 'd/d1', 'd/d2', 'd/e/', 'd/e/e1'])
93
def build_unicode_tree(self):
94
self.requireFeature(UnicodeFilenameFeature)
95
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/',
98
def test_tree_ascii(self):
99
"""Checks the glob expansion and path separation char
101
self.build_ascii_tree()
93
102
self._run_testset([
96
105
[[u'a', u'a' ], [u'a', u'a']],
100
108
[[u'd/'], [u'd/']],
104
111
[[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
106
113
[[u'a?'], [u'a1', u'a2']],
107
114
[[u'a??'], [u'a11', u'a.1']],
108
115
[[u'b[1-2]'], [u'b1', u'b2']],
109
[[u'A?'], [u'a1', u'a2']],
111
117
[[u'd/*'], [u'd/d1', u'd/d2', u'd/e']],
118
[[u'?/*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
119
[[u'*/*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
120
[[u'*/'], [u'c/', u'd/']],
123
def test_backslash_globbing(self):
124
self.requireFeature(BackslashDirSeparatorFeature)
125
self.build_ascii_tree()
112
128
[[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
113
129
[[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
114
130
[[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
115
[[u'*/'], [u'c/', u'd/']],
116
[[u'*\\'], [u'c/', u'd/']]])
131
[[u'*\\'], [u'c/', u'd/']],
134
def test_case_insensitive_globbing(self):
135
self.requireFeature(tests.CaseInsCasePresFilenameFeature)
136
self.build_ascii_tree()
139
[[u'A?'], [u'a1', u'a2']],
118
142
def test_tree_unicode(self):
119
143
"""Checks behaviour with non-ascii filenames"""
120
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
144
self.build_unicode_tree()
121
145
self._run_testset([
123
147
[[u'\u1234'], [u'\u1234']],
134
158
[[u'\u1235/?'], [u'\u1235/\u1235']],
135
159
[[u'\u1235/*'], [u'\u1235/\u1235']],
160
[[u'?/'], [u'\u1235/']],
161
[[u'*/'], [u'\u1235/']],
162
[[u'?/?'], [u'\u1235/\u1235']],
163
[[u'*/*'], [u'\u1235/\u1235']],
166
def test_unicode_backslashes(self):
167
self.requireFeature(BackslashDirSeparatorFeature)
168
self.build_unicode_tree()
171
[[u'\u1235\\'], [u'\u1235/']],
172
[[u'\u1235\\\u1235'], [u'\u1235/\u1235']],
136
173
[[u'\u1235\\?'], [u'\u1235/\u1235']],
137
174
[[u'\u1235\\*'], [u'\u1235/\u1235']],
138
[[u'?/'], [u'\u1235/']],
139
[[u'*/'], [u'\u1235/']],
140
175
[[u'?\\'], [u'\u1235/']],
141
176
[[u'*\\'], [u'\u1235/']],
142
[[u'?/?'], [u'\u1235/\u1235']],
143
[[u'*/*'], [u'\u1235/\u1235']],
144
177
[[u'?\\?'], [u'\u1235/\u1235']],
145
[[u'*\\*'], [u'\u1235/\u1235']]])
178
[[u'*\\*'], [u'\u1235/\u1235']],
147
181
def _run_testset(self, testset):
148
182
for pattern, expected in testset:
222
266
super(TestLocationsPywin32, self).setUp()
223
267
# We perform the exact same tests after disabling the use of ctypes.
224
268
# This causes the implementation to fall back to pywin32.
225
self.old_ctypes = win32utils.has_ctypes
226
win32utils.has_ctypes = False
227
self.addCleanup(self.restoreCtypes)
229
def restoreCtypes(self):
230
win32utils.has_ctypes = self.old_ctypes
269
self.overrideAttr(win32utils, 'has_ctypes', False)
270
# FIXME: this should be done by parametrization -- vila 100123
273
class TestSetHidden(TestCaseInTempDir):
275
def test_unicode_dir(self):
276
# we should handle unicode paths without errors
277
self.requireFeature(UnicodeFilenameFeature)
279
win32utils.set_file_attr_hidden(u'\u1234')
281
def test_dot_bzr_in_unicode_dir(self):
282
# we should not raise traceback if we try to set hidden attribute
283
# on .bzr directory below unicode path
284
self.requireFeature(UnicodeFilenameFeature)
285
os.makedirs(u'\u1234\\.bzr')
286
path = osutils.abspath(u'\u1234\\.bzr')
287
win32utils.set_file_attr_hidden(path)
292
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
294
def assertCommandLine(self, expected, line, single_quotes_allowed=False):
295
# Strictly speaking we should respect parameter order versus glob
296
# 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))
301
def test_glob_paths(self):
302
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
303
self.assertCommandLine([u'a/b.c', u'a/c.c'], 'a/*.c')
304
self.build_tree(['b/', 'b/b.c', 'b/d.c', 'b/d.h'])
305
self.assertCommandLine([u'a/b.c', u'b/b.c'], '*/b.c')
306
self.assertCommandLine([u'a/b.c', u'a/c.c', u'b/b.c', u'b/d.c'],
308
# Bash style, just pass through the argument if nothing matches
309
self.assertCommandLine([u'*/*.qqq'], '*/*.qqq')
311
def test_quoted_globs(self):
312
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
313
self.assertCommandLine([u'a/*.c'], '"a/*.c"')
314
self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
315
self.assertCommandLine([u'a/*.c'], "'a/*.c'",
316
single_quotes_allowed=True)
318
def test_slashes_changed(self):
319
# Quoting doesn't change the supplied args
320
self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
321
self.assertCommandLine([u'a\\*.c'], "'a\\*.c'",
322
single_quotes_allowed=True)
323
# Expands the glob, but nothing matches, swaps slashes
324
self.assertCommandLine([u'a/*.c'], 'a\\*.c')
325
self.assertCommandLine([u'a/?.c'], 'a\\?.c')
326
# No glob, doesn't touch slashes
327
self.assertCommandLine([u'a\\foo.c'], 'a\\foo.c')
329
def test_single_quote_support(self):
330
self.assertCommandLine(["add", "let's-do-it.txt"],
331
"add let's-do-it.txt")
332
self.assertCommandLine(["add", "lets do it.txt"],
333
"add 'lets do it.txt'", single_quotes_allowed=True)
335
def test_case_insensitive_globs(self):
336
self.requireFeature(tests.CaseInsCasePresFilenameFeature)
337
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
338
self.assertCommandLine([u'A/b.c'], 'A/B*')
340
def test_backslashes(self):
341
self.requireFeature(BackslashDirSeparatorFeature)
342
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
343
self.assertCommandLine([u'a/b.c'], 'a\\b*')