~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-23 07:50:15 UTC
  • mfrom: (2376.4.43 bug-support)
  • Revision ID: pqm@pqm.ubuntu.com-20070423075015-340ajk1vo3pzxheu
(robertc) bzr --fixes support to allow recording of bugs that are fixed by commits. (Jonathan Lange, James Henstridge, Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib.tests import TestCase
28
28
from bzrlib.repofmt import knitrepo
29
29
 
 
30
 
30
31
def parse(options, args):
31
32
    parser = option.get_optparser(dict((o.name, o) for o in options))
32
33
    return parser.parse_args(args)
33
34
 
 
35
 
34
36
class OptionTests(TestCase):
35
37
    """Command-line option tests"""
36
38
 
38
40
        """Option parser"""
39
41
        eq = self.assertEquals
40
42
        eq(parse_args(cmd_commit(), ['--help']),
41
 
           ([], {'help': True}))
 
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'}))
46
46
 
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': []}))
51
51
 
52
52
    def test_option_help(self):
53
53
        """Options have help strings."""
112
112
 
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(), ['-']))
 
115
        self.assertEqual(
 
116
            (['-'], {'fixes': []}), parse_args(cmd_commit(), ['-']))
116
117
 
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'),
232
233
                          ])
233
234
 
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>]})
 
235
 
 
236
class TestListOptions(TestCase):
 
237
    """Tests for ListOption, used to specify lists on the command-line."""
 
238
 
 
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)
 
242
 
 
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)
 
247
 
 
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)
 
252
 
 
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)
 
257
 
 
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)
 
263
 
 
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)