/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1616.1.13 by Martin Pool
Fix 'bzr -h' to show help (#35940)
1
# Copyright (C) 2005, 2006 Canonical Ltd
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
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
1185.16.48 by mbp at sourcefrog
- more refactoring of and tests for option parsing
16
1857.1.15 by Aaron Bentley
Add tests for generating an option parser
17
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status
18
from bzrlib.commands import Command, parse_args
19
from bzrlib import errors
20
from bzrlib import option
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
21
from bzrlib.tests import TestCase
1185.16.48 by mbp at sourcefrog
- more refactoring of and tests for option parsing
22
1616.1.13 by Martin Pool
Fix 'bzr -h' to show help (#35940)
23
# TODO: might be nice to just parse them into a structured form and test
24
# against that, rather than running the whole command.
1185.16.48 by mbp at sourcefrog
- more refactoring of and tests for option parsing
25
26
class OptionTests(TestCase):
27
    """Command-line option tests"""
28
29
    def test_parse_args(self):
30
        """Option parser"""
31
        eq = self.assertEquals
32
        eq(parse_args(cmd_commit(), ['--help']),
33
           ([], {'help': True}))
34
        eq(parse_args(cmd_commit(), ['--message=biter']),
35
           ([], {'message': 'biter'}))
36
        ## eq(parse_args(cmd_log(),  '-r 500'.split()),
37
        ##   ([], {'revision': RevisionSpec_int(500)}))
38
1185.16.49 by mbp at sourcefrog
- more refactoring and tests of commandline
39
    def test_no_more_opts(self):
40
        """Terminated options"""
41
        self.assertEquals(parse_args(cmd_commit(), ['--', '-file-with-dashes']),
42
                          (['-file-with-dashes'], {}))
43
1185.16.48 by mbp at sourcefrog
- more refactoring of and tests for option parsing
44
    def test_option_help(self):
45
        """Options have help strings."""
46
        out, err = self.run_bzr_captured(['commit', '--help'])
1857.1.12 by Aaron Bentley
Fix a bunch of test cases that assumed --merge-type or log-format
47
        self.assertContainsRe(out, r'--file(.|\n)*file containing commit'
48
                                   ' message')
49
        self.assertContainsRe(out, r'-h.*--help')
1185.16.48 by mbp at sourcefrog
- more refactoring of and tests for option parsing
50
51
    def test_option_help_global(self):
52
        """Global options have help strings."""
53
        out, err = self.run_bzr_captured(['help', 'status'])
54
        self.assertContainsRe(out, r'--show-ids.*show internal object')
55
56
    def test_option_arg_help(self):
57
        """Help message shows option arguments."""
58
        out, err = self.run_bzr_captured(['help', 'commit'])
59
        self.assertEquals(err, '')
60
        self.assertContainsRe(out, r'--file[ =]MSGFILE')
61
1185.35.24 by Aaron Bentley
Fixed handling of short options not accepted by the command
62
    def test_unknown_short_opt(self):
63
        out, err = self.run_bzr_captured(['help', '-r'], retcode=3)
1857.1.1 by Aaron Bentley
Use optparse for parsing options
64
        self.assertContainsRe(err, r'no such option')
1185.35.24 by Aaron Bentley
Fixed handling of short options not accepted by the command
65
2190.2.1 by Martin Pool
remove global registration of short options
66
    def test_get_short_name(self):
67
        file_opt = option.Option.OPTIONS['file']
2227.1.1 by mbp at sourcefrog
Back out previous incompatible change: Option.short_name is now again
68
        self.assertEquals(file_opt.short_name(), 'F')
2190.2.1 by Martin Pool
remove global registration of short options
69
        force_opt = option.Option.OPTIONS['force']
2227.1.1 by mbp at sourcefrog
Back out previous incompatible change: Option.short_name is now again
70
        self.assertEquals(force_opt.short_name(), None)
2190.2.1 by Martin Pool
remove global registration of short options
71
1852.1.1 by John Arbash Meinel
Allow a plain '-' to be supplied as an argument. bug #50984
72
    def test_allow_dash(self):
73
        """Test that we can pass a plain '-' as an argument."""
74
        self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))
75
1857.1.15 by Aaron Bentley
Add tests for generating an option parser
76
    def test_conversion(self):
77
        def parse(options, args):
78
            parser = option.get_optparser(dict((o.name, o) for o in options))
79
            return parser.parse_args(args)
80
        options = [option.Option('hello')]
81
        opts, args = parse(options, ['--no-hello', '--hello'])
1857.1.16 by Aaron Bentley
Add tests for iter_switches
82
        self.assertEqual(True, opts.hello)
1857.1.15 by Aaron Bentley
Add tests for generating an option parser
83
        opts, args = parse(options, [])
1857.1.16 by Aaron Bentley
Add tests for iter_switches
84
        self.assertEqual(option.OptionParser.DEFAULT_VALUE, opts.hello)
1857.1.15 by Aaron Bentley
Add tests for generating an option parser
85
        opts, args = parse(options, ['--hello', '--no-hello'])
1857.1.22 by Aaron Bentley
Negations set value to False, instead of Optparser.DEFAULT_VALUE
86
        self.assertEqual(False, opts.hello)
1857.1.15 by Aaron Bentley
Add tests for generating an option parser
87
        options = [option.Option('number', type=int)]
88
        opts, args = parse(options, ['--number', '6'])
1857.1.16 by Aaron Bentley
Add tests for iter_switches
89
        self.assertEqual(6, opts.number)
1857.1.15 by Aaron Bentley
Add tests for generating an option parser
90
        self.assertRaises(errors.BzrCommandError, parse, options, ['--number'])
91
        self.assertRaises(errors.BzrCommandError, parse, options, 
92
                          ['--no-number'])
1185.16.48 by mbp at sourcefrog
- more refactoring of and tests for option parsing
93
1857.1.16 by Aaron Bentley
Add tests for iter_switches
94
    def test_iter_switches(self):
95
        opt = option.Option('hello', help='fg')
96
        self.assertEqual(list(opt.iter_switches()),
97
                         [('hello', None, None, 'fg')])
98
        opt = option.Option('hello', help='fg', type=int)
99
        self.assertEqual(list(opt.iter_switches()),
100
                         [('hello', None, 'ARG', 'fg')])
101
        opt = option.Option('hello', help='fg', type=int, argname='gar')
102
        self.assertEqual(list(opt.iter_switches()),
103
                         [('hello', None, 'GAR', 'fg')])
104
1185.16.48 by mbp at sourcefrog
- more refactoring of and tests for option parsing
105
#     >>> parse_args('log -r 500'.split())
106
#     (['log'], {'revision': [<RevisionSpec_int 500>]})
107
#     >>> parse_args('log -r500..600'.split())
108
#     (['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
109
#     >>> parse_args('log -vr500..600'.split())
110
#     (['log'], {'verbose': True, 'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
111
#     >>> parse_args('log -rrevno:500..600'.split()) #the r takes an argument
112
#     (['log'], {'revision': [<RevisionSpec_revno revno:500>, <RevisionSpec_int 600>]})