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