Beispiel #1
0
def test_server():
    """
    Creates a simple server to be tested against the test_client in
    the client module.
    """

    host, port = '', 8080

    def echo(message):
        """
        Test method, an example of how simple it *should* be.
        """
        return message

    def summation(*args):
        return sum(args)

    if '-v' in sys.argv:
        import logging
        config.verbose = True
        logger.addHandler(logging.StreamHandler())
        logger.setLevel(logging.DEBUG)

    server = Server((host, port))
    server.add_handler(echo)
    server.add_handler(echo, 'tree.echo')
    server.add_handler(summation, 'sum')
    server_thread = threading.Thread(target=server.serve)
    server_thread.daemon = True
    server_thread.start()

    print("Server running: %s:%s" % (host, port))

    try:
        while True:
            time.sleep(0.5)
    except KeyboardInterrupt:
        print('Finished.')
        sys.exit()
Beispiel #2
0
def test_server():
    """
    Creates a simple server to be tested against the test_client in
    the client module.
    """
    
    host, port = '', 8080
    
    def echo(message):
        """
        Test method, an example of how simple it *should* be.
        """
        return message
        
    def summation(*args):
        return sum(args)
        
    if '-v' in sys.argv:
        import logging
        config.verbose = True
        logger.addHandler(logging.StreamHandler())
        logger.setLevel(logging.DEBUG)
        
    server = Server((host, port))
    server.add_handler(echo)
    server.add_handler(echo, 'tree.echo')
    server.add_handler(summation, 'sum')
    server_thread = threading.Thread(target=server.serve)
    server_thread.daemon = True
    server_thread.start()
    
    print "Server running: %s:%s" % (host, port)
    
    try:
        while True:
            time.sleep(0.5)
    except KeyboardInterrupt:
        print 'Finished.'
        sys.exit()
    assert result == 5
    print 'Post-batch test completed.'
    
    try:
        conn.echo()
    except Exception, e:
        print 'Bad call had necessary exception.'
        print e.code, e.message
    else:
        print 'ERROR: Did not throw exception for bad call.'
        
    try:
        conn.foobar(5, 6)
    except Exception, e:
        print 'Invalid method threw exception.'
        print e.code, e.message
    else:
        print 'ERROR: Did not throw exception for bad method.'
    
    print '============================='
    print "Tests completed successfully."
    
if __name__ == "__main__":
    import sys    
    import logging
    if '-v' in sys.argv:
        config.verbose = True
        logger.setLevel(logging.DEBUG)
        logger.addHandler(logging.StreamHandler())
    test_client()