32
32
from bzrlib.win32utils import glob_expand, get_app_path
35
class _BackslashDirSeparatorFeature(tests.Feature):
38
class _NeedsGlobExpansionFeature(Feature):
39
os.lstat(os.getcwd() + '\\')
41
return sys.platform == 'win32'
45
43
def feature_name(self):
46
return "Filesystem treats '\\' as a directory separator."
44
return 'Internally performed glob expansion'
48
BackslashDirSeparatorFeature = _BackslashDirSeparatorFeature()
46
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
51
49
class _RequiredModuleFeature(Feature):
73
class TestNeedsGlobExpansionFeature(TestCase):
75
def test_available(self):
76
self.assertEqual(sys.platform == 'win32',
77
NeedsGlobExpansionFeature.available())
80
self.assertTrue("performed" in str(NeedsGlobExpansionFeature))
75
83
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
77
_test_needs_features = []
85
_test_needs_features = [NeedsGlobExpansionFeature]
79
87
def test_empty_tree(self):
80
88
self.build_tree([])
85
93
[['a', 'a'], ['a', 'a']]])
87
def build_ascii_tree(self):
95
def test_tree_ascii(self):
96
"""Checks the glob expansion and path separation char
88
98
self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
89
99
'b', 'b1', 'b2', 'b3',
90
100
'c/', 'c/c1', 'c/c2',
91
101
'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()
102
102
self._run_testset([
104
104
[[u'a'], [u'a']],
105
105
[[u'a', u'a' ], [u'a', u'a']],
107
108
[[u'd'], [u'd']],
108
109
[[u'd/'], [u'd/']],
111
113
[[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
113
115
[[u'a?'], [u'a1', u'a2']],
114
116
[[u'a??'], [u'a11', u'a.1']],
115
117
[[u'b[1-2]'], [u'b1', u'b2']],
118
[[u'A?'], [u'a1', u'a2']],
117
120
[[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()
128
121
[[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
129
122
[[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
130
123
[[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
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']],
124
[[u'*/'], [u'c/', u'd/']],
125
[[u'*\\'], [u'c/', u'd/']]])
142
127
def test_tree_unicode(self):
143
128
"""Checks behaviour with non-ascii filenames"""
144
self.build_unicode_tree()
129
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
145
130
self._run_testset([
147
132
[[u'\u1234'], [u'\u1234']],
158
143
[[u'\u1235/?'], [u'\u1235/\u1235']],
159
144
[[u'\u1235/*'], [u'\u1235/\u1235']],
145
[[u'\u1235\\?'], [u'\u1235/\u1235']],
146
[[u'\u1235\\*'], [u'\u1235/\u1235']],
160
147
[[u'?/'], [u'\u1235/']],
161
148
[[u'*/'], [u'\u1235/']],
149
[[u'?\\'], [u'\u1235/']],
150
[[u'*\\'], [u'\u1235/']],
162
151
[[u'?/?'], [u'\u1235/\u1235']],
163
152
[[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']],
173
[[u'\u1235\\?'], [u'\u1235/\u1235']],
174
[[u'\u1235\\*'], [u'\u1235/\u1235']],
175
[[u'?\\'], [u'\u1235/']],
176
[[u'*\\'], [u'\u1235/']],
177
153
[[u'?\\?'], [u'\u1235/\u1235']],
178
[[u'*\\*'], [u'\u1235/\u1235']],
154
[[u'*\\*'], [u'\u1235/\u1235']]])
181
156
def _run_testset(self, testset):
182
157
for pattern, expected in testset:
266
241
super(TestLocationsPywin32, self).setUp()
267
242
# We perform the exact same tests after disabling the use of ctypes.
268
243
# 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
244
self.old_ctypes = win32utils.has_ctypes
245
win32utils.has_ctypes = False
246
self.addCleanup(self.restoreCtypes)
248
def restoreCtypes(self):
249
win32utils.has_ctypes = self.old_ctypes
273
252
class TestSetHidden(TestCaseInTempDir):
348
327
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
350
329
def assertCommandLine(self, expected, line):
351
# Strictly speaking we should respect parameter order versus glob
352
# expansions, but it's not really worth the effort here
353
self.assertEqual(expected,
354
sorted(win32utils._command_line_to_argv(line)))
330
self.assertEqual(expected, win32utils._command_line_to_argv(line))
356
332
def test_glob_paths(self):
357
333
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
369
345
self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
371
347
def test_slashes_changed(self):
372
# Quoting doesn't change the supplied args
373
self.assertCommandLine([u'a\\*.c'], '"a\\*.c"')
374
# Expands the glob, but nothing matches, swaps slashes
348
self.assertCommandLine([u'a/*.c'], '"a\\*.c"')
349
# Expands the glob, but nothing matches
375
350
self.assertCommandLine([u'a/*.c'], 'a\\*.c')
376
self.assertCommandLine([u'a/?.c'], 'a\\?.c')
377
# No glob, doesn't touch slashes
378
self.assertCommandLine([u'a\\foo.c'], 'a\\foo.c')
351
self.assertCommandLine([u'a/foo.c'], 'a\\foo.c')
380
353
def test_no_single_quote_supported(self):
381
354
self.assertCommandLine(["add", "let's-do-it.txt"],
382
355
"add let's-do-it.txt")
384
def test_case_insensitive_globs(self):
385
self.requireFeature(tests.CaseInsCasePresFilenameFeature)
386
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
387
self.assertCommandLine([u'A/b.c'], 'A/B*')
389
def test_backslashes(self):
390
self.requireFeature(BackslashDirSeparatorFeature)
391
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
392
self.assertCommandLine([u'a/b.c'], 'a\\b*')