~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

  • Committer: Aaron Bentley
  • Date: 2007-01-17 15:39:21 UTC
  • mfrom: (1551.9.35 Aaron's mergeable stuff)
  • mto: This revision was merged to the branch mainline in revision 2239.
  • Revision ID: abentley@panoramicfeedback.com-20070117153921-6pp9ssa2r8n5izoo
Merge bzr.ab, to avoid conflicts submitting

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 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
16
16
 
17
17
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status
18
18
from bzrlib.commands import Command, parse_args
19
 
from bzrlib import errors
20
 
from bzrlib import option
 
19
from bzrlib import (
 
20
        errors,
 
21
        option,
 
22
        symbol_versioning,
 
23
        )
21
24
from bzrlib.tests import TestCase
22
25
 
23
 
# TODO: might be nice to just parse them into a structured form and test
24
 
# against that, rather than running the whole command.
 
26
def parse(options, args):
 
27
    parser = option.get_optparser(dict((o.name, o) for o in options))
 
28
    return parser.parse_args(args)
25
29
 
26
30
class OptionTests(TestCase):
27
31
    """Command-line option tests"""
69
73
        force_opt = option.Option.OPTIONS['force']
70
74
        self.assertEquals(force_opt.short_name(), None)
71
75
 
 
76
    def test_set_short_name(self):
 
77
        o = option.Option('wiggle')
 
78
        o.set_short_name('w')
 
79
        self.assertEqual(o.short_name(), 'w')
 
80
 
 
81
    def test_old_short_names(self):
 
82
        # test the deprecated method for getting and setting short option
 
83
        # names
 
84
        expected_warning = (
 
85
            "access to SHORT_OPTIONS was deprecated in version 0.14."
 
86
            " Set the short option name when constructing the Option.",
 
87
            DeprecationWarning, 2)
 
88
        _warnings = []
 
89
        def capture_warning(message, category, stacklevel=None):
 
90
            _warnings.append((message, category, stacklevel))
 
91
        old_warning_method = symbol_versioning.warn
 
92
        try:
 
93
            # an example of the kind of thing plugins might want to do through
 
94
            # the old interface - make a new option and then give it a short
 
95
            # name.
 
96
            symbol_versioning.set_warning_method(capture_warning)
 
97
            example_opt = option.Option('example', help='example option')
 
98
            option.Option.SHORT_OPTIONS['w'] = example_opt
 
99
            self.assertEqual(example_opt.short_name(), 'w')
 
100
            self.assertEqual([expected_warning], _warnings)
 
101
            # now check that it can actually be parsed with the registered
 
102
            # value
 
103
            opts, args = parse([example_opt], ['-w', 'foo'])
 
104
            self.assertEqual(opts.example, True)
 
105
            self.assertEqual(args, ['foo'])
 
106
        finally:
 
107
            symbol_versioning.set_warning_method(old_warning_method)
 
108
 
72
109
    def test_allow_dash(self):
73
110
        """Test that we can pass a plain '-' as an argument."""
74
111
        self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))
75
112
 
76
113
    def test_conversion(self):
77
 
        def parse(options, args):
78
 
            parser = option.get_optparser(dict((o.name, o) for o in options))
79
 
            return parser.parse_args(args)
80
114
        options = [option.Option('hello')]
81
115
        opts, args = parse(options, ['--no-hello', '--hello'])
82
116
        self.assertEqual(True, opts.hello)