/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_win32utils.py

  • Committer: Andrew Bennetts
  • Date: 2009-10-21 11:13:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4762.
  • Revision ID: andrew.bennetts@canonical.com-20091021111340-w7x4d5yf83qwjncc
Add test that WSGI glue allows request handlers to access paths above that request's. backing transport, so long as it is within the WSGI app's backing transport.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
import os
18
18
import sys
19
19
 
20
 
from bzrlib import (
21
 
    osutils,
22
 
    tests,
23
 
    win32utils,
24
 
    )
 
20
from bzrlib import osutils
25
21
from bzrlib.tests import (
26
22
    Feature,
27
23
    TestCase,
30
26
    UnicodeFilenameFeature,
31
27
    )
32
28
from bzrlib.win32utils import glob_expand, get_app_path
33
 
 
34
 
 
35
 
class _BackslashDirSeparatorFeature(tests.Feature):
 
29
from bzrlib import win32utils
 
30
 
 
31
 
 
32
# Features
 
33
# --------
 
34
 
 
35
class _NeedsGlobExpansionFeature(Feature):
36
36
 
37
37
    def _probe(self):
38
 
        try:
39
 
            os.lstat(os.getcwd() + '\\')
40
 
        except OSError:
41
 
            return False
42
 
        else:
43
 
            return True
 
38
        return sys.platform == 'win32'
44
39
 
45
40
    def feature_name(self):
46
 
        return "Filesystem treats '\\' as a directory separator."
 
41
        return 'Internally performed glob expansion'
47
42
 
48
 
BackslashDirSeparatorFeature = _BackslashDirSeparatorFeature()
 
43
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
49
44
 
50
45
 
51
46
class _RequiredModuleFeature(Feature):
72
67
# Tests
73
68
# -----
74
69
 
 
70
class TestNeedsGlobExpansionFeature(TestCase):
 
71
 
 
72
    def test_available(self):
 
73
        self.assertEqual(sys.platform == 'win32',
 
74
                         NeedsGlobExpansionFeature.available())
 
75
 
 
76
    def test_str(self):
 
77
        self.assertTrue("performed" in str(NeedsGlobExpansionFeature))
 
78
 
 
79
 
75
80
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
76
81
 
77
 
    _test_needs_features = []
 
82
    _test_needs_features = [NeedsGlobExpansionFeature]
78
83
 
79
84
    def test_empty_tree(self):
80
85
        self.build_tree([])
84
89
            [['*'], ['*']],
85
90
            [['a', 'a'], ['a', 'a']]])
86
91
 
87
 
    def build_ascii_tree(self):
 
92
    def test_tree_ascii(self):
 
93
        """Checks the glob expansion and path separation char
 
94
        normalization"""
88
95
        self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
89
96
                         'b', 'b1', 'b2', 'b3',
90
97
                         'c/', 'c/c1', 'c/c2',
91
98
                         '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
99
        self._run_testset([
103
100
            # no wildcards
104
101
            [[u'a'], [u'a']],
105
102
            [[u'a', u'a' ], [u'a', u'a']],
 
103
            [[u'A'], [u'A']],
106
104
 
107
105
            [[u'd'], [u'd']],
108
106
            [[u'd/'], [u'd/']],
 
107
            [[u'd\\'], [u'd/']],
109
108
 
110
109
            # wildcards
111
110
            [[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
113
112
            [[u'a?'], [u'a1', u'a2']],
114
113
            [[u'a??'], [u'a11', u'a.1']],
115
114
            [[u'b[1-2]'], [u'b1', u'b2']],
 
115
            [[u'A?'], [u'a1', u'a2']],
116
116
 
117
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/']],
128
118
            [[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
129
119
            [[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
130
120
            [[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
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
 
            ])
 
121
            [[u'*/'], [u'c/', u'd/']],
 
122
            [[u'*\\'], [u'c/', u'd/']]])
141
123
 
142
124
    def test_tree_unicode(self):
143
125
        """Checks behaviour with non-ascii filenames"""
144
 
        self.build_unicode_tree()
 
126
        self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
145
127
        self._run_testset([
146
128
            # no wildcards
147
129
            [[u'\u1234'], [u'\u1234']],
157
139
 
158
140
            [[u'\u1235/?'], [u'\u1235/\u1235']],
159
141
            [[u'\u1235/*'], [u'\u1235/\u1235']],
 
142
            [[u'\u1235\\?'], [u'\u1235/\u1235']],
 
143
            [[u'\u1235\\*'], [u'\u1235/\u1235']],
160
144
            [[u'?/'], [u'\u1235/']],
161
145
            [[u'*/'], [u'\u1235/']],
 
146
            [[u'?\\'], [u'\u1235/']],
 
147
            [[u'*\\'], [u'\u1235/']],
162
148
            [[u'?/?'], [u'\u1235/\u1235']],
163
149
            [[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']],
173
 
            [[u'\u1235\\?'], [u'\u1235/\u1235']],
174
 
            [[u'\u1235\\*'], [u'\u1235/\u1235']],
175
 
            [[u'?\\'], [u'\u1235/']],
176
 
            [[u'*\\'], [u'\u1235/']],
177
150
            [[u'?\\?'], [u'\u1235/\u1235']],
178
 
            [[u'*\\*'], [u'\u1235/\u1235']],
179
 
            ])
 
151
            [[u'*\\*'], [u'\u1235/\u1235']]])
180
152
 
181
153
    def _run_testset(self, testset):
182
154
        for pattern, expected in testset:
266
238
        super(TestLocationsPywin32, self).setUp()
267
239
        # We perform the exact same tests after disabling the use of ctypes.
268
240
        # 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
 
241
        self.old_ctypes = win32utils.has_ctypes
 
242
        win32utils.has_ctypes = False
 
243
        self.addCleanup(self.restoreCtypes)
 
244
 
 
245
    def restoreCtypes(self):
 
246
        win32utils.has_ctypes = self.old_ctypes
271
247
 
272
248
 
273
249
class TestSetHidden(TestCaseInTempDir):
285
261
        os.makedirs(u'\u1234\\.bzr')
286
262
        path = osutils.abspath(u'\u1234\\.bzr')
287
263
        win32utils.set_file_attr_hidden(path)
288
 
 
289
 
 
290
 
 
291
 
 
292
 
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
293
 
 
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))
300
 
 
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'],
307
 
                               '*/*.c')
308
 
        # Bash style, just pass through the argument if nothing matches
309
 
        self.assertCommandLine([u'*/*.qqq'], '*/*.qqq')
310
 
 
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)
317
 
 
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')
328
 
 
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)
334
 
 
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*')
339
 
 
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*')