32
32
from bzrlib.win32utils import glob_expand, get_app_path
38
class _NeedsGlobExpansionFeature(Feature):
35
class _BackslashDirSeparatorFeature(tests.Feature):
41
return sys.platform == 'win32'
39
os.lstat(os.getcwd() + '\\')
43
45
def feature_name(self):
44
return 'Internally performed glob expansion'
46
return "Filesystem treats '\\' as a directory separator."
46
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
48
BackslashDirSeparatorFeature = _BackslashDirSeparatorFeature()
49
51
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))
83
75
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
85
_test_needs_features = [NeedsGlobExpansionFeature]
77
_test_needs_features = []
87
79
def test_empty_tree(self):
88
80
self.build_tree([])
93
85
[['a', 'a'], ['a', 'a']]])
95
def test_tree_ascii(self):
96
"""Checks the glob expansion and path separation char
87
def build_ascii_tree(self):
98
88
self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
99
89
'b', 'b1', 'b2', 'b3',
100
90
'c/', 'c/c1', 'c/c2',
101
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()
102
102
self._run_testset([
104
104
[[u'a'], [u'a']],
105
105
[[u'a', u'a' ], [u'a', u'a']],
108
107
[[u'd'], [u'd']],
109
108
[[u'd/'], [u'd/']],
113
111
[[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
115
113
[[u'a?'], [u'a1', u'a2']],
116
114
[[u'a??'], [u'a11', u'a.1']],
117
115
[[u'b[1-2]'], [u'b1', u'b2']],
118
[[u'A?'], [u'a1', u'a2']],
120
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()
121
128
[[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
122
129
[[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
123
130
[[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
124
[[u'*/'], [u'c/', u'd/']],
125
[[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']],
127
142
def test_tree_unicode(self):
128
143
"""Checks behaviour with non-ascii filenames"""
129
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
144
self.build_unicode_tree()
130
145
self._run_testset([
132
147
[[u'\u1234'], [u'\u1234']],
143
158
[[u'\u1235/?'], [u'\u1235/\u1235']],
144
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']],
145
173
[[u'\u1235\\?'], [u'\u1235/\u1235']],
146
174
[[u'\u1235\\*'], [u'\u1235/\u1235']],
147
[[u'?/'], [u'\u1235/']],
148
[[u'*/'], [u'\u1235/']],
149
175
[[u'?\\'], [u'\u1235/']],
150
176
[[u'*\\'], [u'\u1235/']],
151
[[u'?/?'], [u'\u1235/\u1235']],
152
[[u'*/*'], [u'\u1235/\u1235']],
153
177
[[u'?\\?'], [u'\u1235/\u1235']],
154
[[u'*\\*'], [u'\u1235/\u1235']]])
178
[[u'*\\*'], [u'\u1235/\u1235']],
156
181
def _run_testset(self, testset):
157
182
for pattern, expected in testset:
241
266
super(TestLocationsPywin32, self).setUp()
242
267
# We perform the exact same tests after disabling the use of ctypes.
243
268
# This causes the implementation to fall back to pywin32.
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
269
self.overrideAttr(win32utils, 'has_ctypes', False)
270
# FIXME: this should be done by parametrization -- vila 100123
252
273
class TestSetHidden(TestCaseInTempDir):
348
369
self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
350
371
def test_slashes_changed(self):
351
self.assertCommandLine([u'a/*.c'], '"a\\*.c"')
352
# Expands the glob, but nothing matches
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
353
375
self.assertCommandLine([u'a/*.c'], 'a\\*.c')
354
self.assertCommandLine([u'a/foo.c'], 'a\\foo.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')
356
380
def test_no_single_quote_supported(self):
357
381
self.assertCommandLine(["add", "let's-do-it.txt"],
358
382
"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*')