1
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status
4
from bzrlib.commands import Command, parse_args
5
from bzrlib import errors
6
from bzrlib import option
3
7
from bzrlib.tests import TestCase
4
from bzrlib.commands import Command, parse_args
5
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status
7
9
# TODO: might be nice to just parse them into a structured form and test
8
10
# against that, rather than running the whole command.
51
53
"""Test that we can pass a plain '-' as an argument."""
52
54
self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))
56
def test_conversion(self):
57
def parse(options, args):
58
parser = option.get_optparser(dict((o.name, o) for o in options))
59
return parser.parse_args(args)
60
options = [option.EnumOption('Lawn mower', str,
61
[('fast', 'mow quickly'), ('careful', 'mow carefully')])]
62
opts, args = parse(options, ['--fast', '--careful'])
63
self.assertEqual(opts.lawn_mower, 'careful')
64
options = [option.EnumOption('Number', int, [('11', 'one'),
66
opts, args = parse(options, ['--22'])
67
self.assertEqual(opts.number, 22)
69
options = [option.Option('hello')]
70
opts, args = parse(options, ['--no-hello', '--hello'])
71
self.assertEqual(opts.hello, True)
72
opts, args = parse(options, [])
73
self.assertEqual(opts.hello, option.OptionParser.DEFAULT_VALUE)
74
opts, args = parse(options, ['--hello', '--no-hello'])
75
self.assertEqual(opts.hello, option.OptionParser.DEFAULT_VALUE)
76
options = [option.Option('number', type=int)]
77
opts, args = parse(options, ['--number', '6'])
78
self.assertEqual(opts.number, 6)
79
self.assertRaises(errors.BzrCommandError, parse, options, ['--number'])
80
self.assertRaises(errors.BzrCommandError, parse, options,
55
83
# >>> parse_args('log -r 500'.split())
56
84
# (['log'], {'revision': [<RevisionSpec_int 500>]})