~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testtransport.py

  • Committer: John Arbash Meinel
  • Date: 2005-07-19 22:13:01 UTC
  • mto: (1185.11.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050719221300-9a7b9bc9d866a9b9
Removed encode/decode from Transport.put/get, added more exceptions that can be thrown.
Added readonly tests for Transports.
Added test for HttpTransport.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
        t = LocalTransport('.')
26
26
        transport_test(self, t)
27
27
 
 
28
class HttpServer(object):
 
29
    """This just encapsulates spawning and stopping
 
30
    an httpserver.
 
31
    """
 
32
    def __init__(self):
 
33
        """This just spawns a separate process to serve files from
 
34
        this directory. Call the .stop() function to kill the
 
35
        process.
 
36
        """
 
37
        from BaseHTTPServer import HTTPServer
 
38
        from SimpleHTTPServer import SimpleHTTPRequestHandler
 
39
        import os
 
40
        if hasattr(os, 'fork'):
 
41
            self.pid = os.fork()
 
42
            if self.pid != 0:
 
43
                return
 
44
        else: # How do we handle windows, which doesn't have fork?
 
45
            raise NotImplementedError('At present HttpServer cannot fork on Windows')
 
46
 
 
47
            # We might be able to do something like os.spawn() for the
 
48
            # python executable, and give it a simple script to run.
 
49
            # but then how do we kill it?
 
50
 
 
51
        try:
 
52
            self.s = HTTPServer(('', 9999), SimpleHTTPRequestHandler)
 
53
            # TODO: Is there something nicer than killing the server when done?
 
54
            self.s.serve_forever()
 
55
        except KeyboardInterrupt:
 
56
            pass
 
57
        os._exit(0)
 
58
 
 
59
    def stop(self):
 
60
        import os
 
61
        if self.pid is None:
 
62
            return
 
63
        if hasattr(os, 'kill'):
 
64
            import signal
 
65
            os.kill(self.pid, signal.SIGINT)
 
66
            os.waitpid(self.pid, 0)
 
67
            self.pid = None
 
68
        else:
 
69
            raise NotImplementedError('At present HttpServer cannot stop on Windows')
 
70
 
 
71
class HttpTransportTest(InTempDir):
 
72
    def runTest(self):
 
73
        from bzrlib.transport import transport_test_ro
 
74
        from bzrlib.http_transport import HttpTransport
 
75
 
 
76
        s = HttpServer()
 
77
 
 
78
        t = HttpTransport('http://localhost:9999/')
 
79
        transport_test_ro(self, t)
 
80
 
 
81
        s.stop()
 
82
 
 
83
 
28
84
 
29
85
TEST_CLASSES = [
30
 
    LocalTransportTest
 
86
    LocalTransportTest,
 
87
    HttpTransportTest
31
88
    ]