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
21
24
from bzrlib.tests import TestCase
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)
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)
76
def test_set_short_name(self):
77
o = option.Option('wiggle')
79
self.assertEqual(o.short_name(), 'w')
81
def test_old_short_names(self):
82
# test the deprecated method for getting and setting short option
85
"access to SHORT_OPTIONS was deprecated in version 0.14."
86
" Set the short option name when constructing the Option.",
87
DeprecationWarning, 2)
89
def capture_warning(message, category, stacklevel=None):
90
_warnings.append((message, category, stacklevel))
91
old_warning_method = symbol_versioning.warn
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
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
103
opts, args = parse([example_opt], ['-w', 'foo'])
104
self.assertEqual(opts.example, True)
105
self.assertEqual(args, ['foo'])
107
symbol_versioning.set_warning_method(old_warning_method)
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(), ['-']))
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)