/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: v.ladeuil+lp at free
  • Date: 2006-10-12 14:29:32 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061012142932-7221fe16d2b48fa3
Shuffle http related test code. Hopefully it ends up at the right place :)

* bzrlib/tests/HttpServer.py: 
New file. bzrlib.tests.ChrootedTestCase use HttpServer. So the
class can't be defined in bzrlib.tests.HTTPUtils because it
creates a circular dependency (bzrlib.tests.HTTPUtils needs to
import bzrlib.tests).

* bzrlib/transport/http/_urllib.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/_pycurl.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/__init__.py: 
Transfer all test related code to either bzrlib.tests.HttpServer
and bzrlib.tests.HTTPUtils.
Fix all use of TransportNotPossible and InvalidURL by prefixing it
by 'errors.' (this seems to be the preferred way in the rest of
bzr).
Get rid of unused imports.

* bzrlib/tests/test_transport.py:
(ReadonlyDecoratorTransportTest.test_local_parameters,
FakeNFSDecoratorTests.test_http_parameters): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_sftp_transport.py:
(set_test_transport_to_sftp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_selftest.py:
(TestTestCaseWithTransport.test_get_readonly_url_http): Use
HttpServer from bzrlib.tests.HttpServer instead of
bzrlib.transport.http.

* bzrlib/tests/test_repository.py: 
Does *not* use HttpServer.

* bzrlib/tests/test_http.py: 
Build on top of bzrlib.tests.HttpServer and bzrlib.tests.HTTPUtils
instead of bzrlib.transport.http.

* bzrlib/tests/test_bzrdir.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_http.py:
(HTTPBranchTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_branch.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/__init__.py:
(ChrootedTestCase.setUp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
 
 
3
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status
 
4
from bzrlib.commands import Command, parse_args
 
5
from bzrlib import errors
 
6
from bzrlib import option
 
7
from bzrlib.tests import TestCase
 
8
 
 
9
# TODO: might be nice to just parse them into a structured form and test
 
10
# against that, rather than running the whole command.
 
11
 
 
12
class OptionTests(TestCase):
 
13
    """Command-line option tests"""
 
14
 
 
15
    def test_parse_args(self):
 
16
        """Option parser"""
 
17
        eq = self.assertEquals
 
18
        eq(parse_args(cmd_commit(), ['--help']),
 
19
           ([], {'help': True}))
 
20
        eq(parse_args(cmd_commit(), ['--message=biter']),
 
21
           ([], {'message': 'biter'}))
 
22
        ## eq(parse_args(cmd_log(),  '-r 500'.split()),
 
23
        ##   ([], {'revision': RevisionSpec_int(500)}))
 
24
 
 
25
    def test_no_more_opts(self):
 
26
        """Terminated options"""
 
27
        self.assertEquals(parse_args(cmd_commit(), ['--', '-file-with-dashes']),
 
28
                          (['-file-with-dashes'], {}))
 
29
 
 
30
    def test_option_help(self):
 
31
        """Options have help strings."""
 
32
        out, err = self.run_bzr_captured(['commit', '--help'])
 
33
        self.assertContainsRe(out, r'--file(.|\n)*file containing commit'
 
34
                                   ' message')
 
35
        self.assertContainsRe(out, r'-h.*--help')
 
36
 
 
37
    def test_option_help_global(self):
 
38
        """Global options have help strings."""
 
39
        out, err = self.run_bzr_captured(['help', 'status'])
 
40
        self.assertContainsRe(out, r'--show-ids.*show internal object')
 
41
 
 
42
    def test_option_arg_help(self):
 
43
        """Help message shows option arguments."""
 
44
        out, err = self.run_bzr_captured(['help', 'commit'])
 
45
        self.assertEquals(err, '')
 
46
        self.assertContainsRe(out, r'--file[ =]MSGFILE')
 
47
 
 
48
    def test_unknown_short_opt(self):
 
49
        out, err = self.run_bzr_captured(['help', '-r'], retcode=3)
 
50
        self.assertContainsRe(err, r'no such option')
 
51
 
 
52
    def test_allow_dash(self):
 
53
        """Test that we can pass a plain '-' as an argument."""
 
54
        self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))
 
55
 
 
56
    def test_conversion(self):
 
57
        def parse(options, args):
 
58
            parser = option.get_optparser(dict((o.name, o) for o in options))
 
59
            return parser.parse_args(args)
 
60
        options = [option.Option('hello')]
 
61
        opts, args = parse(options, ['--no-hello', '--hello'])
 
62
        self.assertEqual(True, opts.hello)
 
63
        opts, args = parse(options, [])
 
64
        self.assertEqual(option.OptionParser.DEFAULT_VALUE, opts.hello)
 
65
        opts, args = parse(options, ['--hello', '--no-hello'])
 
66
        self.assertEqual(False, opts.hello)
 
67
        options = [option.Option('number', type=int)]
 
68
        opts, args = parse(options, ['--number', '6'])
 
69
        self.assertEqual(6, opts.number)
 
70
        self.assertRaises(errors.BzrCommandError, parse, options, ['--number'])
 
71
        self.assertRaises(errors.BzrCommandError, parse, options, 
 
72
                          ['--no-number'])
 
73
 
 
74
    def test_iter_switches(self):
 
75
        opt = option.Option('hello', help='fg')
 
76
        self.assertEqual(list(opt.iter_switches()),
 
77
                         [('hello', None, None, 'fg')])
 
78
        opt = option.Option('hello', help='fg', type=int)
 
79
        self.assertEqual(list(opt.iter_switches()),
 
80
                         [('hello', None, 'ARG', 'fg')])
 
81
        opt = option.Option('hello', help='fg', type=int, argname='gar')
 
82
        self.assertEqual(list(opt.iter_switches()),
 
83
                         [('hello', None, 'GAR', 'fg')])
 
84
 
 
85
#     >>> parse_args('log -r 500'.split())
 
86
#     (['log'], {'revision': [<RevisionSpec_int 500>]})
 
87
#     >>> parse_args('log -r500..600'.split())
 
88
#     (['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
 
89
#     >>> parse_args('log -vr500..600'.split())
 
90
#     (['log'], {'verbose': True, 'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
 
91
#     >>> parse_args('log -rrevno:500..600'.split()) #the r takes an argument
 
92
#     (['log'], {'revision': [<RevisionSpec_revno revno:500>, <RevisionSpec_int 600>]})