/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: Aaron Bentley
  • Date: 2007-01-17 16:13:50 UTC
  • mfrom: (2236 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2240.
  • Revision ID: abentley@panoramicfeedback.com-20070117161350-z0poe4762mzt2mlb
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
    errors,
21
21
    option,
22
22
    repository,
 
23
    symbol_versioning,
23
24
    )
24
25
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status
25
26
from bzrlib.commands import Command, parse_args
26
27
from bzrlib.tests import TestCase
27
28
 
28
 
# TODO: might be nice to just parse them into a structured form and test
29
 
# against that, rather than running the whole command.
 
29
def parse(options, args):
 
30
    parser = option.get_optparser(dict((o.name, o) for o in options))
 
31
    return parser.parse_args(args)
30
32
 
31
33
class OptionTests(TestCase):
32
34
    """Command-line option tests"""
70
72
 
71
73
    def test_get_short_name(self):
72
74
        file_opt = option.Option.OPTIONS['file']
73
 
        self.assertEquals(file_opt.short_name, 'F')
 
75
        self.assertEquals(file_opt.short_name(), 'F')
74
76
        force_opt = option.Option.OPTIONS['force']
75
 
        self.assertEquals(force_opt.short_name, None)
 
77
        self.assertEquals(force_opt.short_name(), None)
 
78
 
 
79
    def test_set_short_name(self):
 
80
        o = option.Option('wiggle')
 
81
        o.set_short_name('w')
 
82
        self.assertEqual(o.short_name(), 'w')
 
83
 
 
84
    def test_old_short_names(self):
 
85
        # test the deprecated method for getting and setting short option
 
86
        # names
 
87
        expected_warning = (
 
88
            "access to SHORT_OPTIONS was deprecated in version 0.14."
 
89
            " Set the short option name when constructing the Option.",
 
90
            DeprecationWarning, 2)
 
91
        _warnings = []
 
92
        def capture_warning(message, category, stacklevel=None):
 
93
            _warnings.append((message, category, stacklevel))
 
94
        old_warning_method = symbol_versioning.warn
 
95
        try:
 
96
            # an example of the kind of thing plugins might want to do through
 
97
            # the old interface - make a new option and then give it a short
 
98
            # name.
 
99
            symbol_versioning.set_warning_method(capture_warning)
 
100
            example_opt = option.Option('example', help='example option')
 
101
            option.Option.SHORT_OPTIONS['w'] = example_opt
 
102
            self.assertEqual(example_opt.short_name(), 'w')
 
103
            self.assertEqual([expected_warning], _warnings)
 
104
            # now check that it can actually be parsed with the registered
 
105
            # value
 
106
            opts, args = parse([example_opt], ['-w', 'foo'])
 
107
            self.assertEqual(opts.example, True)
 
108
            self.assertEqual(args, ['foo'])
 
109
        finally:
 
110
            symbol_versioning.set_warning_method(old_warning_method)
76
111
 
77
112
    def test_allow_dash(self):
78
113
        """Test that we can pass a plain '-' as an argument."""