~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-11-22 03:35:24 UTC
  • mto: This revision was merged to the branch mainline in revision 5547.
  • Revision ID: andrew.bennetts@canonical.com-20101122033524-ouxj0onm3gtkimx3
Remove RepositoryFormatCHK1 and RepositoryFormatCHK2.

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
17
17
"""Tests for win32utils."""
18
18
 
19
19
import os
 
20
import sys
20
21
 
21
22
from bzrlib import (
22
23
    osutils,
24
25
    win32utils,
25
26
    )
26
27
from bzrlib.tests import (
 
28
    Feature,
27
29
    TestCase,
28
30
    TestCaseInTempDir,
29
31
    TestSkipped,
 
32
    UnicodeFilenameFeature,
30
33
    )
31
34
from bzrlib.tests.features import backslashdir_feature
32
35
from bzrlib.win32utils import glob_expand, get_app_path
33
 
from bzrlib.tests import (
34
 
    features,
35
 
    )
36
 
 
37
 
 
38
 
Win32RegistryFeature = features.ModuleAvailableFeature('_winreg')
39
 
CtypesFeature = features.ModuleAvailableFeature('ctypes')
40
 
Win32comShellFeature = features.ModuleAvailableFeature('win32com.shell')
41
 
Win32ApiFeature = features.ModuleAvailableFeature('win32api') 
 
36
 
 
37
 
 
38
class _RequiredModuleFeature(Feature):
 
39
 
 
40
    def __init__(self, mod_name):
 
41
        self.mod_name = mod_name
 
42
        super(_RequiredModuleFeature, self).__init__()
 
43
 
 
44
    def _probe(self):
 
45
        try:
 
46
            __import__(self.mod_name)
 
47
            return True
 
48
        except ImportError:
 
49
            return False
 
50
 
 
51
    def feature_name(self):
 
52
        return self.mod_name
 
53
 
 
54
Win32RegistryFeature = _RequiredModuleFeature('_winreg')
 
55
CtypesFeature = _RequiredModuleFeature('ctypes')
 
56
Win32comShellFeature = _RequiredModuleFeature('win32com.shell')
 
57
Win32ApiFeature = _RequiredModuleFeature('win32api') 
42
58
 
43
59
 
44
60
# Tests
63
79
                         'd/', 'd/d1', 'd/d2', 'd/e/', 'd/e/e1'])
64
80
 
65
81
    def build_unicode_tree(self):
66
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
82
        self.requireFeature(UnicodeFilenameFeature)
67
83
        self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/',
68
84
                         u'\u1235/\u1235'])
69
85
 
104
120
            ])
105
121
 
106
122
    def test_case_insensitive_globbing(self):
107
 
        if os.path.normcase("AbC") == "AbC":
108
 
            self.skip("Test requires case insensitive globbing function")
 
123
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)
109
124
        self.build_ascii_tree()
110
125
        self._run_testset([
111
126
            [[u'A'], [u'A']],
201
216
    def test_appdata_not_using_environment(self):
202
217
        # Test that we aren't falling back to the environment
203
218
        first = win32utils.get_appdata_location()
204
 
        self.overrideEnv("APPDATA", None)
 
219
        self._captureVar("APPDATA", None)
205
220
        self.assertPathsEqual(first, win32utils.get_appdata_location())
206
221
 
207
222
    def test_appdata_matches_environment(self):
218
233
    def test_local_appdata_not_using_environment(self):
219
234
        # Test that we aren't falling back to the environment
220
235
        first = win32utils.get_local_appdata_location()
221
 
        self.overrideEnv("LOCALAPPDATA", None)
 
236
        self._captureVar("LOCALAPPDATA", None)
222
237
        self.assertPathsEqual(first, win32utils.get_local_appdata_location())
223
238
 
224
239
    def test_local_appdata_matches_environment(self):
248
263
 
249
264
    def test_unicode_dir(self):
250
265
        # we should handle unicode paths without errors
251
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
266
        self.requireFeature(UnicodeFilenameFeature)
252
267
        os.mkdir(u'\u1234')
253
268
        win32utils.set_file_attr_hidden(u'\u1234')
254
269
 
255
270
    def test_dot_bzr_in_unicode_dir(self):
256
271
        # we should not raise traceback if we try to set hidden attribute
257
272
        # on .bzr directory below unicode path
258
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
273
        self.requireFeature(UnicodeFilenameFeature)
259
274
        os.makedirs(u'\u1234\\.bzr')
260
275
        path = osutils.abspath(u'\u1234\\.bzr')
261
276
        win32utils.set_file_attr_hidden(path)
311
326
            single_quotes_allowed=True)
312
327
 
313
328
    def test_case_insensitive_globs(self):
314
 
        if os.path.normcase("AbC") == "AbC":
315
 
            self.skip("Test requires case insensitive globbing function")
 
329
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)
316
330
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
317
331
        self.assertCommandLine([u'A/b.c'], 'A/B*')
318
332