def test_iter_switches(self):
     opt = option.Option('hello', help='fg')
     self.assertEqual(list(opt.iter_switches()),
                      [('hello', None, None, 'fg')])
     opt = option.Option('hello', help='fg', type=int)
     self.assertEqual(list(opt.iter_switches()),
                      [('hello', None, 'ARG', 'fg')])
     opt = option.Option('hello', help='fg', type=int, argname='gar')
     self.assertEqual(list(opt.iter_switches()),
                      [('hello', None, 'GAR', 'fg')])
     registry = controldir.ControlDirFormatRegistry()
     bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
     bzrdir.register_metadir(registry, 'two',
             'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
             'two help',
             )
     registry.set_default('one')
     opt = option.RegistryOption('format', 'format help', registry,
                                 value_switches=False)
     self.assertEqual(list(opt.iter_switches()),
                      [('format', None, 'ARG', 'format help')])
     opt = option.RegistryOption('format', 'format help', registry,
                                 value_switches=True)
     self.assertEqual(list(opt.iter_switches()),
                      [('format', None, 'ARG', 'format help'),
                       ('default', None, None, 'one help'),
                       ('one', None, None, 'one help'),
                       ('two', None, None, 'two help'),
                       ])
 def test_registry_conversion(self):
     registry = controldir.ControlDirFormatRegistry()
     bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
     bzrdir.register_metadir(registry, 'two', 'RepositoryFormatKnit1', 'two help')
     bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormatKnit1',
         'two help', hidden=True)
     registry.set_default('one')
     options = [option.RegistryOption('format', '', registry, str)]
     opts, args = self.parse(options, ['--format', 'one'])
     self.assertEqual({'format':'one'}, opts)
     opts, args = self.parse(options, ['--format', 'two'])
     self.assertEqual({'format':'two'}, opts)
     self.assertRaises(errors.BadOptionValue, self.parse, options,
                       ['--format', 'three'])
     self.assertRaises(errors.BzrCommandError, self.parse, options,
                       ['--two'])
     options = [option.RegistryOption('format', '', registry, str,
                value_switches=True)]
     opts, args = self.parse(options, ['--two'])
     self.assertEqual({'format':'two'}, opts)
     opts, args = self.parse(options, ['--two', '--one'])
     self.assertEqual({'format':'one'}, opts)
     opts, args = self.parse(options, ['--two', '--one',
                                       '--format', 'two'])
     self.assertEqual({'format':'two'}, opts)
     options = [option.RegistryOption('format', '', registry, str,
                enum_switch=False)]
     self.assertRaises(errors.BzrCommandError, self.parse, options,
                       ['--format', 'two'])
Example #3
0
 def test_iter_switches(self):
     opt = option.Option('hello', help='fg')
     self.assertEqual(list(opt.iter_switches()),
                      [('hello', None, None, 'fg')])
     opt = option.Option('hello', help='fg', type=int)
     self.assertEqual(list(opt.iter_switches()),
                      [('hello', None, 'ARG', 'fg')])
     opt = option.Option('hello', help='fg', type=int, argname='gar')
     self.assertEqual(list(opt.iter_switches()),
                      [('hello', None, 'GAR', 'fg')])
     registry = controldir.ControlDirFormatRegistry()
     bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
     bzrdir.register_metadir(registry, 'two',
             'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
             'two help',
             )
     registry.set_default('one')
     opt = option.RegistryOption('format', 'format help', registry,
                                 value_switches=False)
     self.assertEqual(list(opt.iter_switches()),
                      [('format', None, 'ARG', 'format help')])
     opt = option.RegistryOption('format', 'format help', registry,
                                 value_switches=True)
     self.assertEqual(list(opt.iter_switches()),
                      [('format', None, 'ARG', 'format help'),
                       ('default', None, None, 'one help'),
                       ('one', None, None, 'one help'),
                       ('two', None, None, 'two help'),
                       ])
Example #4
0
 def test_registry_conversion(self):
     registry = controldir.ControlDirFormatRegistry()
     bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
     bzrdir.register_metadir(registry, 'two', 'RepositoryFormatKnit1', 'two help')
     bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormatKnit1',
         'two help', hidden=True)
     registry.set_default('one')
     options = [option.RegistryOption('format', '', registry, str)]
     opts, args = self.parse(options, ['--format', 'one'])
     self.assertEqual({'format':'one'}, opts)
     opts, args = self.parse(options, ['--format', 'two'])
     self.assertEqual({'format':'two'}, opts)
     self.assertRaises(errors.BadOptionValue, self.parse, options,
                       ['--format', 'three'])
     self.assertRaises(errors.BzrCommandError, self.parse, options,
                       ['--two'])
     options = [option.RegistryOption('format', '', registry, str,
                value_switches=True)]
     opts, args = self.parse(options, ['--two'])
     self.assertEqual({'format':'two'}, opts)
     opts, args = self.parse(options, ['--two', '--one'])
     self.assertEqual({'format':'one'}, opts)
     opts, args = self.parse(options, ['--two', '--one',
                                       '--format', 'two'])
     self.assertEqual({'format':'two'}, opts)
     options = [option.RegistryOption('format', '', registry, str,
                enum_switch=False)]
     self.assertRaises(errors.BzrCommandError, self.parse, options,
                       ['--format', 'two'])
 def test_help(self):
     registry = controldir.ControlDirFormatRegistry()
     bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
     bzrdir.register_metadir(registry, 'two',
         'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
         'two help',
         )
     bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormat7', 'hidden help',
         hidden=True)
     registry.set_default('one')
     options = [option.RegistryOption('format', 'format help', registry,
                str, value_switches=True, title='Formats')]
     parser = option.get_optparser(dict((o.name, o) for o in options))
     value = parser.format_option_help()
     self.assertContainsRe(value, 'format.*format help')
     self.assertContainsRe(value, 'one.*one help')
     self.assertContainsRe(value, 'Formats:\n *--format')
     self.assertNotContainsRe(value, 'hidden help')
Example #6
0
 def test_help(self):
     registry = controldir.ControlDirFormatRegistry()
     bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
     bzrdir.register_metadir(registry, 'two',
         'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
         'two help',
         )
     bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormat7', 'hidden help',
         hidden=True)
     registry.set_default('one')
     options = [option.RegistryOption('format', 'format help', registry,
                str, value_switches=True, title='Formats')]
     parser = option.get_optparser(dict((o.name, o) for o in options))
     value = parser.format_option_help()
     self.assertContainsRe(value, 'format.*format help')
     self.assertContainsRe(value, 'one.*one help')
     self.assertContainsRe(value, 'Formats:\n *--format')
     self.assertNotContainsRe(value, 'hidden help')