~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_win32utils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-28 00:25:32 UTC
  • mfrom: (5264.1.2 command-help-bug-177500)
  • Revision ID: pqm@pqm.ubuntu.com-20100528002532-9bzj1fajyxckd1rg
(lifeless) Stop raising at runtime when a command has no help,
 instead have a test in the test suite that checks all known command objects.
 (Robert Collins)

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,
53
54
Win32RegistryFeature = _RequiredModuleFeature('_winreg')
54
55
CtypesFeature = _RequiredModuleFeature('ctypes')
55
56
Win32comShellFeature = _RequiredModuleFeature('win32com.shell')
56
 
Win32ApiFeature = _RequiredModuleFeature('win32api') 
57
57
 
58
58
 
59
59
# Tests
119
119
            ])
120
120
 
121
121
    def test_case_insensitive_globbing(self):
122
 
        if os.path.normcase("AbC") == "AbC":
123
 
            self.skip("Test requires case insensitive globbing function")
 
122
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)
124
123
        self.build_ascii_tree()
125
124
        self._run_testset([
126
125
            [[u'A'], [u'A']],
190
189
        # typical windows users should have wordpad in the system
191
190
        # but there is problem: its path has the format REG_EXPAND_SZ
192
191
        # so naive attempt to get the path is not working
193
 
        self.requireFeature(Win32ApiFeature)
194
192
        for a in ('wordpad', 'wordpad.exe'):
195
193
            p = get_app_path(a)
196
194
            d, b = os.path.split(p)
216
214
    def test_appdata_not_using_environment(self):
217
215
        # Test that we aren't falling back to the environment
218
216
        first = win32utils.get_appdata_location()
219
 
        self.overrideEnv("APPDATA", None)
 
217
        self._captureVar("APPDATA", None)
220
218
        self.assertPathsEqual(first, win32utils.get_appdata_location())
221
219
 
222
220
    def test_appdata_matches_environment(self):
233
231
    def test_local_appdata_not_using_environment(self):
234
232
        # Test that we aren't falling back to the environment
235
233
        first = win32utils.get_local_appdata_location()
236
 
        self.overrideEnv("LOCALAPPDATA", None)
 
234
        self._captureVar("LOCALAPPDATA", None)
237
235
        self.assertPathsEqual(first, win32utils.get_local_appdata_location())
238
236
 
239
237
    def test_local_appdata_matches_environment(self):
278
276
 
279
277
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
280
278
 
281
 
    def assertCommandLine(self, expected, line, argv=None,
282
 
            single_quotes_allowed=False):
 
279
    def assertCommandLine(self, expected, line, single_quotes_allowed=False):
283
280
        # Strictly speaking we should respect parameter order versus glob
284
281
        # 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,
 
282
        argv = win32utils._command_line_to_argv(line,
288
283
                single_quotes_allowed=single_quotes_allowed)
289
284
        self.assertEqual(expected, sorted(argv))
290
285
 
318
313
 
319
314
    def test_single_quote_support(self):
320
315
        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)
 
316
            "add let's-do-it.txt")
 
317
        self.assertCommandLine(["add", "lets do it.txt"],
 
318
            "add 'lets do it.txt'", single_quotes_allowed=True)
327
319
 
328
320
    def test_case_insensitive_globs(self):
329
 
        if os.path.normcase("AbC") == "AbC":
330
 
            self.skip("Test requires case insensitive globbing function")
 
321
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)
331
322
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
332
323
        self.assertCommandLine([u'A/b.c'], 'A/B*')
333
324
 
335
326
        self.requireFeature(backslashdir_feature)
336
327
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
337
328
        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/*"])