~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

(gz) Fix style checking testcase for option help (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
341
341
 
342
342
    def get_builtin_command_options(self):
343
343
        g = []
344
 
        for cmd_name in sorted(commands.all_command_names()):
 
344
        commands.install_bzr_command_hooks()
 
345
        for cmd_name in sorted(commands.builtin_command_names()):
345
346
            cmd = commands.get_cmd_object(cmd_name)
346
347
            for opt_name, opt in sorted(cmd.options().items()):
347
348
                g.append((cmd_name, opt))
 
349
        self.assert_(g)
348
350
        return g
349
351
 
350
 
    def test_global_options_used(self):
351
 
        # In the distant memory, options could only be declared globally.  Now
352
 
        # we prefer to declare them in the command, unless like -r they really
353
 
        # are used very widely with the exact same meaning.  So this checks
354
 
        # for any that should be garbage collected.
355
 
        g = dict(option.Option.OPTIONS.items())
356
 
        used_globals = {}
357
 
        msgs = []
358
 
        for cmd_name in sorted(commands.all_command_names()):
359
 
            cmd = commands.get_cmd_object(cmd_name)
360
 
            for option_or_name in sorted(cmd.takes_options):
361
 
                if not isinstance(option_or_name, basestring):
362
 
                    self.assertIsInstance(option_or_name, option.Option)
363
 
                elif not option_or_name in g:
364
 
                    msgs.append("apparent reference to undefined "
365
 
                        "global option %r from %r"
366
 
                        % (option_or_name, cmd))
367
 
                else:
368
 
                    used_globals.setdefault(option_or_name, []).append(cmd_name)
369
 
        unused_globals = set(g.keys()) - set(used_globals.keys())
370
 
        # not enforced because there might be plugins that use these globals
371
 
        ## for option_name in sorted(unused_globals):
372
 
        ##    msgs.append("unused global option %r" % option_name)
373
 
        ## for option_name, cmds in sorted(used_globals.items()):
374
 
        ##     if len(cmds) <= 1:
375
 
        ##         msgs.append("global option %r is only used by %r"
376
 
        ##                 % (option_name, cmds))
377
 
        if msgs:
378
 
            self.fail("problems with global option definitions:\n"
379
 
                    + '\n'.join(msgs))
380
 
 
381
352
    def test_option_grammar(self):
382
353
        msgs = []
383
354
        # Option help should be written in sentence form, and have a final
395
366
            self.fail("The following options don't match the style guide:\n"
396
367
                    + '\n'.join(msgs))
397
368
 
 
369
 
 
370
class TestOptionMisc(TestCase):
 
371
 
398
372
    def test_is_hidden(self):
399
373
        registry = controldir.ControlDirFormatRegistry()
400
374
        bzrdir.register_metadir(registry, 'hidden', 'HiddenFormat',