/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/http_server.py

Rework test_script a little bit.


Don't allow someone to request a stdin request to echo.
Echo never reads from stdin, it just echos its arguments.
You use 'cat' if you want to read from stdin.

A few other fixes because the tests were using filenames
that are actually illegal on Windows, rather than just
nonexistant.


Change the exception handling for commands so that
unknown errors don't get silently squashed and then
turn into hard-to-debug errors later.

test_script now passes on Windows.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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
31
31
import urlparse
32
32
 
33
33
from bzrlib import transport
34
 
from bzrlib.tests import test_server
35
34
from bzrlib.transport import local
36
35
 
37
36
 
319
318
        self.test_case_server = test_case_server
320
319
        self._home_dir = test_case_server._home_dir
321
320
 
322
 
    def stop_server(self):
 
321
    def tearDown(self):
323
322
         """Called to clean-up the server.
324
323
 
325
324
         Since the server may be (surely is, even) in a blocking listen, we
348
347
             # 'Socket is not connected' can also occur on OSX, with a
349
348
             # "regular" ENOTCONN (when something went wrong during test case
350
349
             # setup leading to self.setUp() *not* being called but
351
 
             # self.stop_server() still being called -- vila20081106
 
350
             # self.tearDown() still being called -- vila20081106
352
351
             if not len(e.args) or e.args[0] not in (errno.ENOTCONN, 10057):
353
352
                 raise
354
353
         # Let the server properly close the socket
463
462
                raise httplib.UnknownProtocol(proto_vers)
464
463
            else:
465
464
                self._httpd = self.create_httpd(serv_cls, rhandler)
466
 
            self.host, self.port = self._httpd.socket.getsockname()
 
465
            host, self.port = self._httpd.socket.getsockname()
467
466
        return self._httpd
468
467
 
469
468
    def _http_start(self):
495
494
            except socket.timeout:
496
495
                pass
497
496
            except (socket.error, select.error), e:
498
 
                if (e[0] == errno.EBADF
499
 
                    or (sys.platform == 'win32' and e[0] == 10038)):
500
 
                    # Starting with python-2.6, handle_request may raise socket
501
 
                    # or select exceptions when the server is shut down (as we
502
 
                    # do).
503
 
                    # 10038 = WSAENOTSOCK
504
 
                    # http://msdn.microsoft.com/en-us/library/ms740668%28VS.85%29.aspx
505
 
                    pass
506
 
                else:
507
 
                    raise
 
497
               if e[0] == errno.EBADF:
 
498
                   # Starting with python-2.6, handle_request may raise socket
 
499
                   # or select exceptions when the server is shut down (as we
 
500
                   # do).
 
501
                   pass
 
502
               else:
 
503
                   raise
508
504
 
509
505
    def _get_remote_url(self, path):
510
506
        path_parts = path.split(os.path.sep)
522
518
        """Capture Server log output."""
523
519
        self.logs.append(format % args)
524
520
 
525
 
    def start_server(self, backing_transport_server=None):
526
 
        """See bzrlib.transport.Server.start_server.
 
521
    def setUp(self, backing_transport_server=None):
 
522
        """See bzrlib.transport.Server.setUp.
527
523
 
528
524
        :param backing_transport_server: The transport that requests over this
529
525
            protocol should be forwarded to. Note that this is currently not
531
527
        """
532
528
        # XXX: TODO: make the server back onto vfs_server rather than local
533
529
        # disk.
534
 
        if not (backing_transport_server is None
535
 
                or isinstance(backing_transport_server,
536
 
                              test_server.LocalURLServer)):
 
530
        if not (backing_transport_server is None or \
 
531
                isinstance(backing_transport_server, local.LocalURLServer)):
537
532
            raise AssertionError(
538
533
                "HTTPServer currently assumes local transport, got %s" % \
539
534
                backing_transport_server)
559
554
        self._http_starting.release()
560
555
        self.logs = []
561
556
 
562
 
    def stop_server(self):
563
 
        self._httpd.stop_server()
 
557
    def tearDown(self):
 
558
        """See bzrlib.transport.Server.tearDown."""
 
559
        self._httpd.tearDown()
564
560
        self._http_running = False
565
561
        # We don't need to 'self._http_thread.join()' here since the thread is
566
562
        # a daemonic one and will be garbage collected anyway. Joining just