/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import re
18
18
 
42
42
        # to cmd_commit, when they are meant to be about option parsing in
43
43
        # general.
44
44
        self.assertEqual(parse_args(cmd_commit(), ['--help']),
45
 
           ([], {'exclude': [], 'fixes': [], 'help': True}))
 
45
           ([], {'author': [], 'exclude': [], 'fixes': [], 'help': True}))
46
46
        self.assertEqual(parse_args(cmd_commit(), ['--message=biter']),
47
 
           ([], {'exclude': [], 'fixes': [], 'message': 'biter'}))
 
47
           ([], {'author': [], 'exclude': [], 'fixes': [], 'message': 'biter'}))
48
48
 
49
49
    def test_no_more_opts(self):
50
50
        """Terminated options"""
51
51
        self.assertEqual(parse_args(cmd_commit(), ['--', '-file-with-dashes']),
52
 
                          (['-file-with-dashes'], {'exclude': [], 'fixes': []}))
 
52
                          (['-file-with-dashes'], {'author': [], 'exclude': [], 'fixes': []}))
53
53
 
54
54
    def test_option_help(self):
55
55
        """Options have help strings."""
102
102
        self.assertRaises(errors.BzrCommandError, self.parse, options,
103
103
                          ['--no-number'])
104
104
 
 
105
    def test_is_hidden(self):
 
106
        self.assertTrue(option.Option('foo', hidden=True).is_hidden('foo'))
 
107
        self.assertFalse(option.Option('foo', hidden=False).is_hidden('foo'))
 
108
 
105
109
    def test_registry_conversion(self):
106
110
        registry = bzrdir.BzrDirFormatRegistry()
107
111
        registry.register_metadir('one', 'RepositoryFormat7', 'one help')
320
324
 
321
325
    def get_builtin_command_options(self):
322
326
        g = []
323
 
        for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
324
 
            cmd = cmd_class()
 
327
        for cmd_name in sorted(commands.all_command_names()):
 
328
            cmd = commands.get_cmd_object(cmd_name)
325
329
            for opt_name, opt in sorted(cmd.options().items()):
326
330
                g.append((cmd_name, opt))
327
331
        return g
334
338
        g = dict(option.Option.OPTIONS.items())
335
339
        used_globals = {}
336
340
        msgs = []
337
 
        for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
338
 
            for option_or_name in sorted(cmd_class.takes_options):
 
341
        for cmd_name in sorted(commands.all_command_names()):
 
342
            cmd = commands.get_cmd_object(cmd_name)
 
343
            for option_or_name in sorted(cmd.takes_options):
339
344
                if not isinstance(option_or_name, basestring):
340
345
                    self.assertIsInstance(option_or_name, option.Option)
341
346
                elif not option_or_name in g:
342
347
                    msgs.append("apparent reference to undefined "
343
348
                        "global option %r from %r"
344
 
                        % (option_or_name, cmd_class))
 
349
                        % (option_or_name, cmd))
345
350
                else:
346
351
                    used_globals.setdefault(option_or_name, []).append(cmd_name)
347
352
        unused_globals = set(g.keys()) - set(used_globals.keys())
362
367
        # period and be all on a single line, because the display code will
363
368
        # wrap it.
364
369
        option_re = re.compile(r'^[A-Z][^\n]+\.$')
365
 
        for scope, option in self.get_builtin_command_options():
366
 
            if not option.help:
367
 
                msgs.append('%-16s %-16s %s' %
368
 
                       ((scope or 'GLOBAL'), option.name, 'NO HELP'))
369
 
            elif not option_re.match(option.help):
370
 
                msgs.append('%-16s %-16s %s' %
371
 
                        ((scope or 'GLOBAL'), option.name, option.help))
 
370
        for scope, opt in self.get_builtin_command_options():
 
371
            if not opt.help:
 
372
                msgs.append('%-16s %-16s %s' %
 
373
                       ((scope or 'GLOBAL'), opt.name, 'NO HELP'))
 
374
            elif not option_re.match(opt.help):
 
375
                msgs.append('%-16s %-16s %s' %
 
376
                        ((scope or 'GLOBAL'), opt.name, opt.help))
372
377
        if msgs:
373
378
            self.fail("The following options don't match the style guide:\n"
374
379
                    + '\n'.join(msgs))