~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-28 07:08:42 UTC
  • mfrom: (2380 +trunk)
  • mto: (2018.5.146 hpss)
  • mto: This revision was merged to the branch mainline in revision 2414.
  • Revision ID: andrew.bennetts@canonical.com-20070328070842-r843houy668oxb9o
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status
26
26
from bzrlib.commands import Command, parse_args
27
27
from bzrlib.tests import TestCase
 
28
from bzrlib.repofmt import knitrepo
28
29
 
29
30
def parse(options, args):
30
31
    parser = option.get_optparser(dict((o.name, o) for o in options))
137
138
        registry = bzrdir.BzrDirFormatRegistry()
138
139
        registry.register_metadir('one', 'RepositoryFormat7', 'one help')
139
140
        registry.register_metadir('two', 'RepositoryFormatKnit1', 'two help')
 
141
        registry.register_metadir('hidden', 'RepositoryFormatKnit1',
 
142
            'two help', hidden=True)
140
143
        registry.set_default('one')
141
144
        options = [option.RegistryOption('format', '', registry, str)]
142
145
        opts, args = self.parse(options, ['--format', 'one'])
156
159
        opts, args = self.parse(options, ['--two', '--one',
157
160
                                          '--format', 'two'])
158
161
        self.assertEqual({'format':'two'}, opts)
 
162
        options = [option.RegistryOption('format', '', registry, str,
 
163
                   enum_switch=False)]
 
164
        self.assertRaises(errors.BzrCommandError, self.parse, options,
 
165
                          ['--format', 'two'])
159
166
 
160
167
    def test_registry_converter(self):
161
168
        options = [option.RegistryOption('format', '',
162
169
                   bzrdir.format_registry, bzrdir.format_registry.make_bzrdir)]
163
170
        opts, args = self.parse(options, ['--format', 'knit'])
164
171
        self.assertIsInstance(opts.format.repository_format,
165
 
                              repository.RepositoryFormatKnit1)
 
172
                              knitrepo.RepositoryFormatKnit1)
 
173
 
 
174
    def test_from_kwargs(self):
 
175
        my_option = option.RegistryOption.from_kwargs('my-option',
 
176
            help='test option', short='be short', be_long='go long')
 
177
        self.assertEqual(['my-option'],
 
178
            [x[0] for x in my_option.iter_switches()])
 
179
        my_option = option.RegistryOption.from_kwargs('my-option',
 
180
            help='test option', title="My option", short='be short',
 
181
            be_long='go long', value_switches=True)
 
182
        self.assertEqual(['my-option', 'be-long', 'short'],
 
183
            [x[0] for x in my_option.iter_switches()])
166
184
 
167
185
    def test_help(self):
168
186
        registry = bzrdir.BzrDirFormatRegistry()
169
187
        registry.register_metadir('one', 'RepositoryFormat7', 'one help')
170
 
        registry.register_metadir('two', 'RepositoryFormatKnit1', 'two help')
 
188
        registry.register_metadir('two',
 
189
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
190
            'two help',
 
191
            )
 
192
        registry.register_metadir('hidden', 'RepositoryFormat7', 'hidden help',
 
193
            hidden=True)
171
194
        registry.set_default('one')
172
195
        options = [option.RegistryOption('format', 'format help', registry,
173
196
                   str, value_switches=True, title='Formats')]
176
199
        self.assertContainsRe(value, 'format.*format help')
177
200
        self.assertContainsRe(value, 'one.*one help')
178
201
        self.assertContainsRe(value, 'Formats:\n *--format')
 
202
        self.assertNotContainsRe(value, 'hidden help')
179
203
 
180
204
    def test_iter_switches(self):
181
205
        opt = option.Option('hello', help='fg')
189
213
                         [('hello', None, 'GAR', 'fg')])
190
214
        registry = bzrdir.BzrDirFormatRegistry()
191
215
        registry.register_metadir('one', 'RepositoryFormat7', 'one help')
192
 
        registry.register_metadir('two', 'RepositoryFormatKnit1', 'two help')
 
216
        registry.register_metadir('two',
 
217
                'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
218
                'two help',
 
219
                )
193
220
        registry.set_default('one')
194
221
        opt = option.RegistryOption('format', 'format help', registry,
195
222
                                    value_switches=False)