38
40
"""Option parser"""
39
41
eq = self.assertEquals
40
42
eq(parse_args(cmd_commit(), ['--help']),
43
([], {'fixes': [], 'help': True}))
42
44
eq(parse_args(cmd_commit(), ['--message=biter']),
43
([], {'message': 'biter'}))
44
## eq(parse_args(cmd_log(), '-r 500'.split()),
45
## ([], {'revision': RevisionSpec_int(500)}))
45
([], {'fixes': [], 'message': 'biter'}))
47
47
def test_no_more_opts(self):
48
48
"""Terminated options"""
49
49
self.assertEquals(parse_args(cmd_commit(), ['--', '-file-with-dashes']),
50
(['-file-with-dashes'], {}))
50
(['-file-with-dashes'], {'fixes': []}))
52
52
def test_option_help(self):
53
53
"""Options have help strings."""
113
113
def test_allow_dash(self):
114
114
"""Test that we can pass a plain '-' as an argument."""
115
self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))
116
(['-'], {'fixes': []}), parse_args(cmd_commit(), ['-']))
117
118
def parse(self, options, args):
118
119
parser = option.get_optparser(dict((o.name, o) for o in options))
231
232
('two', None, None, 'two help'),
234
# >>> parse_args('log -r 500'.split())
235
# (['log'], {'revision': [<RevisionSpec_int 500>]})
236
# >>> parse_args('log -r500..600'.split())
237
# (['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
238
# >>> parse_args('log -vr500..600'.split())
239
# (['log'], {'verbose': True, 'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
240
# >>> parse_args('log -rrevno:500..600'.split()) #the r takes an argument
241
# (['log'], {'revision': [<RevisionSpec_revno revno:500>, <RevisionSpec_int 600>]})
236
class TestListOptions(TestCase):
237
"""Tests for ListOption, used to specify lists on the command-line."""
239
def parse(self, options, args):
240
parser = option.get_optparser(dict((o.name, o) for o in options))
241
return parser.parse_args(args)
243
def test_list_option(self):
244
options = [option.ListOption('hello', type=str)]
245
opts, args = self.parse(options, ['--hello=world', '--hello=sailor'])
246
self.assertEqual(['world', 'sailor'], opts.hello)
248
def test_list_option_no_arguments(self):
249
options = [option.ListOption('hello', type=str)]
250
opts, args = self.parse(options, [])
251
self.assertEqual([], opts.hello)
253
def test_list_option_with_int_type(self):
254
options = [option.ListOption('hello', type=int)]
255
opts, args = self.parse(options, ['--hello=2', '--hello=3'])
256
self.assertEqual([2, 3], opts.hello)
258
def test_list_option_with_int_type_can_be_reset(self):
259
options = [option.ListOption('hello', type=int)]
260
opts, args = self.parse(options, ['--hello=2', '--hello=3',
261
'--hello=-', '--hello=5'])
262
self.assertEqual([5], opts.hello)
264
def test_list_option_can_be_reset(self):
265
"""Passing an option of '-' to a list option should reset the list."""
266
options = [option.ListOption('hello', type=str)]
267
opts, args = self.parse(
268
options, ['--hello=a', '--hello=b', '--hello=-', '--hello=c'])
269
self.assertEqual(['c'], opts.hello)