~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_win32utils.py

  • Committer: Andrew Bennetts
  • Date: 2010-02-12 04:33:05 UTC
  • mfrom: (5031 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5032.
  • Revision ID: andrew.bennetts@canonical.com-20100212043305-ujdbsdoviql2t7i3
MergeĀ lp:bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
from bzrlib.win32utils import glob_expand, get_app_path
33
33
 
34
34
 
35
 
# Features
36
 
# --------
37
 
 
38
 
class _NeedsGlobExpansionFeature(Feature):
 
35
class _BackslashDirSeparatorFeature(tests.Feature):
39
36
 
40
37
    def _probe(self):
41
 
        return sys.platform == 'win32'
 
38
        try:
 
39
            os.lstat(os.getcwd() + '\\')
 
40
        except OSError:
 
41
            return False
 
42
        else:
 
43
            return True
42
44
 
43
45
    def feature_name(self):
44
 
        return 'Internally performed glob expansion'
 
46
        return "Filesystem treats '\\' as a directory separator."
45
47
 
46
 
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
 
48
BackslashDirSeparatorFeature = _BackslashDirSeparatorFeature()
47
49
 
48
50
 
49
51
class _RequiredModuleFeature(Feature):
70
72
# Tests
71
73
# -----
72
74
 
73
 
class TestNeedsGlobExpansionFeature(TestCase):
74
 
 
75
 
    def test_available(self):
76
 
        self.assertEqual(sys.platform == 'win32',
77
 
                         NeedsGlobExpansionFeature.available())
78
 
 
79
 
    def test_str(self):
80
 
        self.assertTrue("performed" in str(NeedsGlobExpansionFeature))
81
 
 
82
 
 
83
75
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
84
76
 
85
 
    _test_needs_features = [NeedsGlobExpansionFeature]
 
77
    _test_needs_features = []
86
78
 
87
79
    def test_empty_tree(self):
88
80
        self.build_tree([])
92
84
            [['*'], ['*']],
93
85
            [['a', 'a'], ['a', 'a']]])
94
86
 
95
 
    def test_tree_ascii(self):
96
 
        """Checks the glob expansion and path separation char
97
 
        normalization"""
 
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'])
 
92
 
 
93
    def build_unicode_tree(self):
 
94
        self.requireFeature(UnicodeFilenameFeature)
 
95
        self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/',
 
96
                         u'\u1235/\u1235'])
 
97
 
 
98
    def test_tree_ascii(self):
 
99
        """Checks the glob expansion and path separation char
 
100
        normalization"""
 
101
        self.build_ascii_tree()
102
102
        self._run_testset([
103
103
            # no wildcards
104
104
            [[u'a'], [u'a']],
105
105
            [[u'a', u'a' ], [u'a', u'a']],
106
 
            [[u'A'], [u'A']],
107
106
 
108
107
            [[u'd'], [u'd']],
109
108
            [[u'd/'], [u'd/']],
110
 
            [[u'd\\'], [u'd/']],
111
109
 
112
110
            # wildcards
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']],
119
116
 
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/']],
 
121
            ])
 
122
 
 
123
    def test_backslash_globbing(self):
 
124
        self.requireFeature(BackslashDirSeparatorFeature)
 
125
        self.build_ascii_tree()
 
126
        self._run_testset([
 
127
            [[u'd\\'], [u'd/']],
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/']],
 
132
            ])
 
133
 
 
134
    def test_case_insensitive_globbing(self):
 
135
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)
 
136
        self.build_ascii_tree()
 
137
        self._run_testset([
 
138
            [[u'A'], [u'A']],
 
139
            [[u'A?'], [u'a1', u'a2']],
 
140
            ])
126
141
 
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([
131
146
            # no wildcards
132
147
            [[u'\u1234'], [u'\u1234']],
142
157
 
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']],
 
164
            ])
 
165
 
 
166
    def test_unicode_backslashes(self):
 
167
        self.requireFeature(BackslashDirSeparatorFeature)
 
168
        self.build_unicode_tree()
 
169
        self._run_testset([
 
170
            # no wildcards
 
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']],
 
179
            ])
155
180
 
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)
247
 
 
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
250
271
 
251
272
 
252
273
class TestSetHidden(TestCaseInTempDir):
348
369
        self.assertCommandLine([u"'a/*.c'"], "'a/*.c'")
349
370
 
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')
355
379
 
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")
 
383
 
 
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*')
 
388
 
 
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*')