/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: mbp at sourcefrog
  • Date: 2007-01-12 03:52:12 UTC
  • mto: (2230.1.1 short-options)
  • mto: This revision was merged to the branch mainline in revision 2231.
  • Revision ID: mbp@sourcefrog.net-20070112035212-rgjqu83owh9s5s2p
add test that legacy SHORT_OPTIONS really works, and set_short_name

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
        )
24
24
from bzrlib.tests import TestCase
25
25
 
26
 
# TODO: might be nice to just parse them into a structured form and test
27
 
# against that, rather than running the whole command.
 
26
def parse(options, args):
 
27
    parser = option.get_optparser(dict((o.name, o) for o in options))
 
28
    return parser.parse_args(args)
28
29
 
29
30
class OptionTests(TestCase):
30
31
    """Command-line option tests"""
72
73
        force_opt = option.Option.OPTIONS['force']
73
74
        self.assertEquals(force_opt.short_name(), None)
74
75
 
 
76
    def test_set_short_name(self):
 
77
        o = option.Option('wiggle')
 
78
        o.set_short_name('w')
 
79
        self.assertEqual(o.short_name(), 'w')
 
80
 
75
81
    def test_old_short_names(self):
76
82
        # test the deprecated method for getting and setting short option
77
83
        # names
88
94
            # the old interface - make a new option and then give it a short
89
95
            # name.
90
96
            symbol_versioning.set_warning_method(capture_warning)
91
 
            working_tree_opt = option.Option('working tree', help='example option')
92
 
            option.Option.SHORT_OPTIONS['w'] = working_tree_opt
93
 
            self.assertEqual(working_tree_opt.short_name(), 'w')
 
97
            example_opt = option.Option('example', help='example option')
 
98
            option.Option.SHORT_OPTIONS['w'] = example_opt
 
99
            self.assertEqual(example_opt.short_name(), 'w')
94
100
            self.assertEqual([expected_warning], _warnings)
 
101
            # now check that it can actually be parsed with the registered
 
102
            # value
 
103
            opts, args = parse([example_opt], ['-w', 'foo'])
 
104
            self.assertEqual(opts.example, True)
 
105
            self.assertEqual(args, ['foo'])
95
106
        finally:
96
107
            symbol_versioning.set_warning_method(old_warning_method)
97
108
 
100
111
        self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))
101
112
 
102
113
    def test_conversion(self):
103
 
        def parse(options, args):
104
 
            parser = option.get_optparser(dict((o.name, o) for o in options))
105
 
            return parser.parse_args(args)
106
114
        options = [option.Option('hello')]
107
115
        opts, args = parse(options, ['--no-hello', '--hello'])
108
116
        self.assertEqual(True, opts.hello)