~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_win32utils.py

  • Committer: Jelmer Vernooij
  • Date: 2010-04-30 11:03:59 UTC
  • mto: This revision was merged to the branch mainline in revision 5197.
  • Revision ID: jelmer@samba.org-20100430110359-ow3e3grh7sxy93pa
Remove more unused imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Tests for win32utils."""
18
 
 
19
17
import os
 
18
import sys
20
19
 
21
20
from bzrlib import (
22
21
    osutils,
30
29
    TestSkipped,
31
30
    UnicodeFilenameFeature,
32
31
    )
33
 
from bzrlib.tests.features import backslashdir_feature
34
32
from bzrlib.win32utils import glob_expand, get_app_path
35
33
 
36
34
 
 
35
class _BackslashDirSeparatorFeature(tests.Feature):
 
36
 
 
37
    def _probe(self):
 
38
        try:
 
39
            os.lstat(os.getcwd() + '\\')
 
40
        except OSError:
 
41
            return False
 
42
        else:
 
43
            return True
 
44
 
 
45
    def feature_name(self):
 
46
        return "Filesystem treats '\\' as a directory separator."
 
47
 
 
48
BackslashDirSeparatorFeature = _BackslashDirSeparatorFeature()
 
49
 
 
50
 
37
51
class _RequiredModuleFeature(Feature):
38
52
 
39
53
    def __init__(self, mod_name):
53
67
Win32RegistryFeature = _RequiredModuleFeature('_winreg')
54
68
CtypesFeature = _RequiredModuleFeature('ctypes')
55
69
Win32comShellFeature = _RequiredModuleFeature('win32com.shell')
56
 
Win32ApiFeature = _RequiredModuleFeature('win32api') 
57
70
 
58
71
 
59
72
# Tests
108
121
            ])
109
122
 
110
123
    def test_backslash_globbing(self):
111
 
        self.requireFeature(backslashdir_feature)
 
124
        self.requireFeature(BackslashDirSeparatorFeature)
112
125
        self.build_ascii_tree()
113
126
        self._run_testset([
114
127
            [[u'd\\'], [u'd/']],
119
132
            ])
120
133
 
121
134
    def test_case_insensitive_globbing(self):
122
 
        if os.path.normcase("AbC") == "AbC":
123
 
            self.skip("Test requires case insensitive globbing function")
 
135
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)
124
136
        self.build_ascii_tree()
125
137
        self._run_testset([
126
138
            [[u'A'], [u'A']],
152
164
            ])
153
165
 
154
166
    def test_unicode_backslashes(self):
155
 
        self.requireFeature(backslashdir_feature)
 
167
        self.requireFeature(BackslashDirSeparatorFeature)
156
168
        self.build_unicode_tree()
157
169
        self._run_testset([
158
170
            # no wildcards
190
202
        # typical windows users should have wordpad in the system
191
203
        # but there is problem: its path has the format REG_EXPAND_SZ
192
204
        # so naive attempt to get the path is not working
193
 
        self.requireFeature(Win32ApiFeature)
194
205
        for a in ('wordpad', 'wordpad.exe'):
195
206
            p = get_app_path(a)
196
207
            d, b = os.path.split(p)
216
227
    def test_appdata_not_using_environment(self):
217
228
        # Test that we aren't falling back to the environment
218
229
        first = win32utils.get_appdata_location()
219
 
        self.overrideEnv("APPDATA", None)
 
230
        self._captureVar("APPDATA", None)
220
231
        self.assertPathsEqual(first, win32utils.get_appdata_location())
221
232
 
222
233
    def test_appdata_matches_environment(self):
233
244
    def test_local_appdata_not_using_environment(self):
234
245
        # Test that we aren't falling back to the environment
235
246
        first = win32utils.get_local_appdata_location()
236
 
        self.overrideEnv("LOCALAPPDATA", None)
 
247
        self._captureVar("LOCALAPPDATA", None)
237
248
        self.assertPathsEqual(first, win32utils.get_local_appdata_location())
238
249
 
239
250
    def test_local_appdata_matches_environment(self):
276
287
        win32utils.set_file_attr_hidden(path)
277
288
 
278
289
 
 
290
 
 
291
 
279
292
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
280
293
 
281
 
    def assertCommandLine(self, expected, line, argv=None,
282
 
            single_quotes_allowed=False):
 
294
    def assertCommandLine(self, expected, line, single_quotes_allowed=False):
283
295
        # Strictly speaking we should respect parameter order versus glob
284
296
        # expansions, but it's not really worth the effort here
285
 
        if argv is None:
286
 
            argv = [line]
287
 
        argv = win32utils._command_line_to_argv(line, argv,
 
297
        argv = win32utils._command_line_to_argv(line,
288
298
                single_quotes_allowed=single_quotes_allowed)
289
299
        self.assertEqual(expected, sorted(argv))
290
300
 
318
328
 
319
329
    def test_single_quote_support(self):
320
330
        self.assertCommandLine(["add", "let's-do-it.txt"],
321
 
            "add let's-do-it.txt",
322
 
            ["add", "let's-do-it.txt"])
323
 
        self.expectFailure("Using single quotes breaks trimming from argv",
324
 
            self.assertCommandLine, ["add", "lets do it.txt"],
325
 
            "add 'lets do it.txt'", ["add", "'lets", "do", "it.txt'"],
326
 
            single_quotes_allowed=True)
 
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)
327
334
 
328
335
    def test_case_insensitive_globs(self):
329
 
        if os.path.normcase("AbC") == "AbC":
330
 
            self.skip("Test requires case insensitive globbing function")
 
336
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)
331
337
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
332
338
        self.assertCommandLine([u'A/b.c'], 'A/B*')
333
339
 
334
340
    def test_backslashes(self):
335
 
        self.requireFeature(backslashdir_feature)
 
341
        self.requireFeature(BackslashDirSeparatorFeature)
336
342
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
337
343
        self.assertCommandLine([u'a/b.c'], 'a\\b*')
338
 
 
339
 
    def test_with_pdb(self):
340
 
        """Check stripping Python arguments before bzr script per lp:587868"""
341
 
        self.assertCommandLine([u"rocks"], "-m pdb rocks", ["rocks"])
342
 
        self.build_tree(['d/', 'd/f1', 'd/f2'])
343
 
        self.assertCommandLine([u"rm", u"x*"], "-m pdb rm x*", ["rm", u"x*"])
344
 
        self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",
345
 
            ["add", u"d/*"])