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  | 
|
| 
1852.1.1
by John Arbash Meinel
 Allow a plain '-' to be supplied as an argument. bug #50984  | 
66  | 
def test_allow_dash(self):  | 
67  | 
"""Test that we can pass a plain '-' as an argument."""  | 
|
68  | 
self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))  | 
|
69  | 
||
| 
1857.1.15
by Aaron Bentley
 Add tests for generating an option parser  | 
70  | 
def test_conversion(self):  | 
71  | 
def parse(options, args):  | 
|
72  | 
parser = option.get_optparser(dict((o.name, o) for o in options))  | 
|
73  | 
return parser.parse_args(args)  | 
|
74  | 
options = [option.Option('hello')]  | 
|
75  | 
opts, args = parse(options, ['--no-hello', '--hello'])  | 
|
| 
1857.1.16
by Aaron Bentley
 Add tests for iter_switches  | 
76  | 
self.assertEqual(True, opts.hello)  | 
| 
1857.1.15
by Aaron Bentley
 Add tests for generating an option parser  | 
77  | 
opts, args = parse(options, [])  | 
| 
1857.1.16
by Aaron Bentley
 Add tests for iter_switches  | 
78  | 
self.assertEqual(option.OptionParser.DEFAULT_VALUE, opts.hello)  | 
| 
1857.1.15
by Aaron Bentley
 Add tests for generating an option parser  | 
79  | 
opts, args = parse(options, ['--hello', '--no-hello'])  | 
| 
1857.1.22
by Aaron Bentley
 Negations set value to False, instead of Optparser.DEFAULT_VALUE  | 
80  | 
self.assertEqual(False, opts.hello)  | 
| 
1857.1.15
by Aaron Bentley
 Add tests for generating an option parser  | 
81  | 
options = [option.Option('number', type=int)]  | 
82  | 
opts, args = parse(options, ['--number', '6'])  | 
|
| 
1857.1.16
by Aaron Bentley
 Add tests for iter_switches  | 
83  | 
self.assertEqual(6, opts.number)  | 
| 
1857.1.15
by Aaron Bentley
 Add tests for generating an option parser  | 
84  | 
self.assertRaises(errors.BzrCommandError, parse, options, ['--number'])  | 
85  | 
self.assertRaises(errors.BzrCommandError, parse, options,  | 
|
86  | 
['--no-number'])  | 
|
| 
1185.16.48
by mbp at sourcefrog
 - more refactoring of and tests for option parsing  | 
87  | 
|
| 
1857.1.16
by Aaron Bentley
 Add tests for iter_switches  | 
88  | 
def test_iter_switches(self):  | 
89  | 
opt = option.Option('hello', help='fg')  | 
|
90  | 
self.assertEqual(list(opt.iter_switches()),  | 
|
91  | 
[('hello', None, None, 'fg')])  | 
|
92  | 
opt = option.Option('hello', help='fg', type=int)  | 
|
93  | 
self.assertEqual(list(opt.iter_switches()),  | 
|
94  | 
[('hello', None, 'ARG', 'fg')])  | 
|
95  | 
opt = option.Option('hello', help='fg', type=int, argname='gar')  | 
|
96  | 
self.assertEqual(list(opt.iter_switches()),  | 
|
97  | 
[('hello', None, 'GAR', 'fg')])  | 
|
98  | 
||
| 
1185.16.48
by mbp at sourcefrog
 - more refactoring of and tests for option parsing  | 
99  | 
#     >>> parse_args('log -r 500'.split())
 | 
100  | 
#     (['log'], {'revision': [<RevisionSpec_int 500>]})
 | 
|
101  | 
#     >>> parse_args('log -r500..600'.split())
 | 
|
102  | 
#     (['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
 | 
|
103  | 
#     >>> parse_args('log -vr500..600'.split())
 | 
|
104  | 
#     (['log'], {'verbose': True, 'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
 | 
|
105  | 
#     >>> parse_args('log -rrevno:500..600'.split()) #the r takes an argument
 | 
|
106  | 
#     (['log'], {'revision': [<RevisionSpec_revno revno:500>, <RevisionSpec_int 600>]})
 |