/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/blackbox/test_serve.py

Add test for exporting command help.
It checks ":Usage:" is not exported.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
18
18
"""Tests of the bzr serve command."""
19
19
 
20
20
import os
21
 
import os.path
22
21
import signal
23
 
import subprocess
24
 
import sys
25
22
import thread
26
23
import threading
27
24
 
28
25
from bzrlib import (
29
26
    builtins,
30
 
    debug,
31
27
    errors,
32
28
    osutils,
33
29
    revision as _mod_revision,
 
30
    transport,
34
31
    urlutils,
35
32
    )
36
33
from bzrlib.branch import Branch
37
34
from bzrlib.bzrdir import BzrDir
38
35
from bzrlib.smart import client, medium
39
 
from bzrlib.smart.server import BzrServerFactory, SmartTCPServer
 
36
from bzrlib.smart.server import (
 
37
    BzrServerFactory,
 
38
    SmartTCPServer,
 
39
    )
40
40
from bzrlib.tests import (
41
41
    TestCaseWithMemoryTransport,
42
42
    TestCaseWithTransport,
43
 
    TestSkipped,
44
43
    )
45
44
from bzrlib.trace import mutter
46
 
from bzrlib.transport import get_transport, remote
 
45
from bzrlib.transport import remote
47
46
 
48
47
 
49
48
class TestBzrServeBase(TestCaseWithTransport):
52
51
                                *func_args, **func_kwargs):
53
52
        """Run 'bzr serve', and run the given func in a thread once the server
54
53
        has started.
55
 
        
 
54
 
56
55
        When 'func' terminates, the server will be terminated too.
57
 
        
 
56
 
58
57
        Returns stdout and stderr.
59
58
        """
60
59
        # install hook
82
81
            'run_bzr_serve_then_func hook')
83
82
        # start a TCP server
84
83
        try:
85
 
            out, err = self.run_bzr(['serve'] + list(serve_args))
 
84
            out, err = self.run_bzr(['serve'] + list(serve_args), retcode=retcode)
86
85
        except KeyboardInterrupt, e:
87
86
            out, err = e.args
88
87
        return out, err
94
93
        super(TestBzrServe, self).setUp()
95
94
        self.disable_missing_extensions_warning()
96
95
 
 
96
    def test_server_exception_with_hook(self):
 
97
        """test exception hook works to catch exceptions from server"""
 
98
        def hook(exception):
 
99
            from bzrlib.trace import note
 
100
            note("catching exception")
 
101
            return True
 
102
        SmartTCPServer.hooks.install_named_hook(
 
103
            'server_exception', hook,
 
104
            'test_server_except_hook hook')
 
105
        args = []
 
106
        out, err = self.run_bzr_serve_then_func(args, retcode=0)
 
107
        self.assertEqual('listening on port: 4155\ncatching exception\n', err)
 
108
 
 
109
    def test_server_exception_no_hook(self):
 
110
        """test exception without hook returns error"""
 
111
        args = []
 
112
        out, err = self.run_bzr_serve_then_func(args, retcode=3)
 
113
 
97
114
    def assertInetServerShutsdownCleanly(self, process):
98
115
        """Shutdown the server process looking for errors."""
99
116
        # Shutdown the server: the server should shut down when it cannot read
163
180
        url = 'bzr://localhost:%d/' % port
164
181
        self.permit_url(url)
165
182
        return process, url
166
 
    
 
183
 
167
184
    def test_bzr_serve_quiet(self):
168
185
        self.make_branch('.')
169
186
        args = ['--port', 'localhost:0', '--quiet']
192
209
    def test_bzr_serve_port_readonly(self):
193
210
        """bzr server should provide a read only filesystem by default."""
194
211
        process, url = self.start_server_port()
195
 
        transport = get_transport(url)
196
 
        self.assertRaises(errors.TransportNotPossible, transport.mkdir, 'adir')
 
212
        t = transport.get_transport(url)
 
213
        self.assertRaises(errors.TransportNotPossible, t.mkdir, 'adir')
197
214
        self.assertServerFinishesCleanly(process)
198
215
 
199
216
    def test_bzr_serve_port_readwrite(self):
224
241
        # -Dhpss, and does drop some hpss logging to the file.
225
242
        self.make_branch('.')
226
243
        log_fname = os.getcwd() + '/server.log'
227
 
        self._captureVar('BZR_LOG', log_fname)
 
244
        self.overrideEnv('BZR_LOG', log_fname)
228
245
        process, transport = self.start_server_inet(['-Dhpss'])
229
246
        branch = BzrDir.open_from_transport(transport).open_branch()
230
247
        self.make_read_requests(branch)
275
292
 
276
293
class TestUserdirExpansion(TestCaseWithMemoryTransport):
277
294
 
278
 
    def fake_expanduser(self, path):
 
295
    @staticmethod
 
296
    def fake_expanduser(path):
279
297
        """A simple, environment-independent, function for the duration of this
280
298
        test.
281
299
 
333
351
        self.assertEqual(base_url, self.bzr_serve_transport.base)
334
352
        self.assertEqual(base_dir,
335
353
            server_maker.get_base_path(self.bzr_serve_transport))
336