~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

  • Committer: Aaron Bentley
  • Date: 2007-01-17 16:32:40 UTC
  • mto: This revision was merged to the branch mainline in revision 2240.
  • Revision ID: abentley@panoramicfeedback.com-20070117163240-lj6ttc8m57mdrsj0
Zap trailing whitespace

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
    def parse(self, options, args):
117
117
        parser = option.get_optparser(dict((o.name, o) for o in options))
118
118
        return parser.parse_args(args)
119
 
        
 
119
 
120
120
    def test_conversion(self):
121
121
        options = [option.Option('hello')]
122
122
        opts, args = self.parse(options, ['--no-hello', '--hello'])
128
128
        options = [option.Option('number', type=int)]
129
129
        opts, args = self.parse(options, ['--number', '6'])
130
130
        self.assertEqual(6, opts.number)
131
 
        self.assertRaises(errors.BzrCommandError, self.parse, options, 
 
131
        self.assertRaises(errors.BzrCommandError, self.parse, options,
132
132
                          ['--number'])
133
 
        self.assertRaises(errors.BzrCommandError, self.parse, options, 
 
133
        self.assertRaises(errors.BzrCommandError, self.parse, options,
134
134
                          ['--no-number'])
135
135
 
136
136
    def test_registry_conversion(self):
143
143
        self.assertEqual({'format':'one'}, opts)
144
144
        opts, args = self.parse(options, ['--format', 'two'])
145
145
        self.assertEqual({'format':'two'}, opts)
146
 
        self.assertRaises(errors.BadOptionValue, self.parse, options, 
 
146
        self.assertRaises(errors.BadOptionValue, self.parse, options,
147
147
                          ['--format', 'three'])
148
 
        self.assertRaises(errors.BzrCommandError, self.parse, options, 
 
148
        self.assertRaises(errors.BzrCommandError, self.parse, options,
149
149
                          ['--two'])
150
 
        options = [option.RegistryOption('format', '', registry, str, 
 
150
        options = [option.RegistryOption('format', '', registry, str,
151
151
                   value_switches=True)]
152
152
        opts, args = self.parse(options, ['--two'])
153
153
        self.assertEqual({'format':'two'}, opts)
154
154
        opts, args = self.parse(options, ['--two', '--one'])
155
155
        self.assertEqual({'format':'one'}, opts)
156
 
        opts, args = self.parse(options, ['--two', '--one', 
 
156
        opts, args = self.parse(options, ['--two', '--one',
157
157
                                          '--format', 'two'])
158
158
        self.assertEqual({'format':'two'}, opts)
159
159
 
160
160
    def test_registry_converter(self):
161
 
        options = [option.RegistryOption('format', '', 
 
161
        options = [option.RegistryOption('format', '',
162
162
                   bzrdir.format_registry, builtins.get_format_type)]
163
163
        opts, args = self.parse(options, ['--format', 'knit'])
164
164
        self.assertIsInstance(opts.format.repository_format,
198
198
                                    value_switches=True)
199
199
        self.assertEqual(list(opt.iter_switches()),
200
200
                         [('format', None, 'ARG', 'format help'),
201
 
                          ('default', None, None, 'one help'), 
202
 
                          ('one', None, None, 'one help'), 
203
 
                          ('two', None, None, 'two help'), 
 
201
                          ('default', None, None, 'one help'),
 
202
                          ('one', None, None, 'one help'),
 
203
                          ('two', None, None, 'two help'),
204
204
                          ])
205
205
 
206
206
#     >>> parse_args('log -r 500'.split())