当前位置: 首页>>代码示例>>Python>>正文


Python testing.get_unused_port函数代码示例

本文整理汇总了Python中tornado.testing.get_unused_port函数的典型用法代码示例。如果您正苦于以下问题:Python get_unused_port函数的具体用法?Python get_unused_port怎么用?Python get_unused_port使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_unused_port函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

 def setUp(self):
     AsyncTestCase.setUp(self)
     self.response_callback = SpyMethod()
     self.server = PServer(self.response_callback, NetStringConn, io_loop = self.io_loop)
     self.server.handle_stream = SpyMethod()
     self.port = get_unused_port()
     self.server.listen(self.port)
开发者ID:robert-zaremba,项目名称:tornado-pserver,代码行数:7,代码来源:test_pserver.py

示例2: make_iostream_pair

    def make_iostream_pair(self, **kwargs):
        port = get_unused_port()
        [listener] = netutil.bind_sockets(port, '127.0.0.1',
                                          family=socket.AF_INET)
        streams = [None, None]

        def accept_callback(connection, address):
            streams[0] = self._make_server_iostream(connection, **kwargs)
            if isinstance(streams[0], SSLIOStream):
                # HACK: The SSL handshake won't complete (and
                # therefore the client connect callback won't be
                # run)until the server side has tried to do something
                # with the connection.  For these tests we want both
                # sides to connect before we do anything else with the
                # connection, so we must cause some dummy activity on the
                # server.  If this turns out to be useful for real apps
                # it should have a cleaner interface.
                streams[0]._add_io_state(IOLoop.READ)
            self.stop()

        def connect_callback():
            streams[1] = client_stream
            self.stop()
        netutil.add_accept_handler(listener, accept_callback,
                                   io_loop=self.io_loop)
        client_stream = self._make_client_iostream(socket.socket(), **kwargs)
        client_stream.connect(('127.0.0.1', port),
                              callback=connect_callback)
        self.wait(condition=lambda: all(streams))
        self.io_loop.remove_handler(listener.fileno())
        listener.close()
        return streams
开发者ID:EdwinGriffin,项目名称:TornadoSchoolWebsite,代码行数:32,代码来源:iostream_test.py

示例3: test_chunked_close

    def test_chunked_close(self):
        # test case in which chunks spread read-callback processing
        # over several ioloop iterations, but the connection is already closed.
        port = get_unused_port()
        (sock,) = netutil.bind_sockets(port, address="127.0.0.1")
        with closing(sock):
            def write_response(stream, request_data):
                stream.write(b("""\
HTTP/1.1 200 OK
Transfer-Encoding: chunked

1
1
1
2
0

""").replace(b("\n"), b("\r\n")), callback=stream.close)
            def accept_callback(conn, address):
                # fake an HTTP server using chunked encoding where the final chunks
                # and connection close all happen at once
                stream = IOStream(conn, io_loop=self.io_loop)
                stream.read_until(b("\r\n\r\n"),
                                  functools.partial(write_response, stream))
            netutil.add_accept_handler(sock, accept_callback, self.io_loop)
            self.http_client.fetch("http://127.0.0.1:%d/" % port, self.stop)
            resp = self.wait()
            resp.rethrow()
            self.assertEqual(resp.body, b("12"))
开发者ID:e1ven,项目名称:Waymoot,代码行数:29,代码来源:httpclient_test.py

示例4: main

def main():
  """Creates a Metadata object, fetches the default dictionary of
  metadata values, and prints them.

  If --mock was specified on the command line, creates an http server
  for testing.
  """
  query_ip = Metadata._QUERY_IP

  # If a mock server was requested for testing, start it here.
  options.parse_command_line()
  if options.options.mock:
    from tornado import testing
    port = testing.get_unused_port()
    class Handler(web.RequestHandler):
      def get(self, path):
        self.write(path.split("/")[-1])
    application = web.Application([ (r"/(.*)", Handler), ])
    application.listen(port)
    query_ip = "localhost:{0}".format(port)

  def _MetadataCallback(metadata):
    print metadata
    ioloop.IOLoop.current().stop()

  Metadata(callback=_MetadataCallback, query_ip=query_ip)
  ioloop.IOLoop.current().start()
  return 0
开发者ID:00zhengfu00,项目名称:viewfinder,代码行数:28,代码来源:ami_metadata.py

示例5: test_100_continue

    def test_100_continue(self):
        # testing if httpclient is able to skip 100 continue responses.
        # to test without httpserver implementation, using
        # raw response as same as httpclient_test.test_chunked_close.
        port = get_unused_port()
        (sock,) = netutil.bind_sockets(port, address="127.0.0.1")
        with closing(sock):
            def write_response(stream, request_data):
                stream.write(b("""\
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Content-Length: 6

hjkl
""").replace(b("\n"), b("\r\n")), callback=stream.close)
            def accept_callback(conn, address):
                # fake an HTTP server using chunked encoding where the final chunks
                # and connection close all happen at once
                stream = IOStream(conn, io_loop=self.io_loop)
                stream.read_until(b("\r\n\r\n"),
                                  functools.partial(write_response, stream))
            netutil.add_accept_handler(sock, accept_callback, self.io_loop)
            self.http_client.fetch("http://127.0.0.1:%d/" % port, self.stop,
                                   headers={"Expect": "100-continue"})
            resp = self.wait()
            resp.rethrow()
            self.assertEqual(resp.body, b("hjkl\r\n"))
开发者ID:yyuu,项目名称:tornado,代码行数:28,代码来源:simple_httpclient_test.py

示例6: start_twisted_server

 def start_twisted_server(self):
     class HelloResource(Resource):
         isLeaf = True
         def render_GET(self, request):
             return "Hello from twisted!"
     site = Site(HelloResource())
     self.twisted_port = get_unused_port()
     self.reactor.listenTCP(self.twisted_port, site, interface='127.0.0.1')
开发者ID:e1ven,项目名称:Waymoot,代码行数:8,代码来源:twisted_test.py

示例7: start_tornado_server

 def start_tornado_server(self):
     class HelloHandler(RequestHandler):
         def get(self):
             self.write("Hello from tornado!")
     app = Application([('/', HelloHandler)],
                       log_function=lambda x: None)
     self.tornado_port = get_unused_port()
     app.listen(self.tornado_port, address='127.0.0.1', io_loop=self.io_loop)
开发者ID:Frostman,项目名称:tornado,代码行数:8,代码来源:twisted_test.py

示例8: test_multiple_add

 def test_multiple_add(self):
     [sock] = bind_sockets(get_unused_port(), "127.0.0.1", family=socket.AF_INET)
     try:
         self.io_loop.add_handler(sock.fileno(), lambda fd, events: None, IOLoop.READ)
         # Attempting to add the same handler twice fails
         # (with a platform-dependent exception)
         self.assertRaises(Exception, self.io_loop.add_handler, sock.fileno(), lambda fd, events: None, IOLoop.READ)
     finally:
         sock.close()
开发者ID:igorsobreira,项目名称:tornado,代码行数:9,代码来源:ioloop_test.py

示例9: get_app

    def get_app(self):
        (_, self.temp_file_path) = tempfile.mkstemp(
            prefix='eventlogging-service-test',
            text=True,
        )
        writers = ['file://' + self.temp_file_path]
        application = EventLoggingService(writers, None, get_unused_port())

        return application
开发者ID:wikimedia,项目名称:eventlogging,代码行数:9,代码来源:test_service.py

示例10: __init__

 def __init__(self, video_filename):
     self.port = get_unused_port()
     app = Application([
         ('/api/Episode/(\d+)', FakeSonarr.EpisodeHandler),
         ('/api/EpisodeFile/(\d+)', FakeSonarr.EpisodeFileHandler, dict(video_filename=video_filename))
     ])
     self.server = HTTPServer(app)
     self.server.listen(self.port)
     self.url = 'http://localhost:%s' % (self.port,)
开发者ID:NigelRook,项目名称:superliminal,代码行数:9,代码来源:fakesonarr.py

示例11: get_app

    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)
        config.update({"TASKS_CHUNK": 15,
                       "BACKENDS": {"gottwall.backends.tcpip.TCPIPBackend": {
                           "PORT": get_unused_port()}}})

        app = AggregatorApplication(config)
        app.configure_app(tornado.ioloop.IOLoop().instance())
        return app
开发者ID:GottWall,项目名称:GottWall,代码行数:10,代码来源:app.py

示例12: setUp

    def setUp(self):
        AsyncTestCase.setUp(self)
        port = get_unused_port()
        sock = netutil.bind_sockets(port, 'localhost', family=socket.AF_INET)[0]
        setattr(self, '_AsyncHTTPTestCase__port', port)
        self.__port = port

        self.http_client = self.get_http_client()
        self._app = self.get_app()
        self.http_server = self.get_http_server()
        self.http_server.add_sockets([sock])
开发者ID:heynemann,项目名称:wight,代码行数:11,代码来源:base.py

示例13: __init__

 def __init__(self, video_filename):
     self.port = get_unused_port()
     self.movie_id = 'tt9876543'
     app = Application([
         ('/api/'+API_KEY+'/media.get', FakeCouchPotato.MediaDotGetHandler, dict(owner=self))
     ])
     self.server = HTTPServer(app)
     self.server.listen(self.port)
     self.url = 'http://localhost:%s' % (self.port,)
     self.video_filename = video_filename
     self.return_files = True
开发者ID:NigelRook,项目名称:superliminal,代码行数:11,代码来源:fakecouchpotato.py

示例14: test_endpoint_document

    def test_endpoint_document(self, mock_ioloop, mock_parse_args):
        mock_ioloop.time = mock.Mock(return_value=time())
        mock_ioloop.current.return_value = mock_ioloop

        args = mock.MagicMock()
        args.port = get_unused_port()
        args.settings = "{}"
        args.endpoints = ["document"]
        mock_parse_args.return_value = args

        start_server()
开发者ID:gakhov,项目名称:api.boilerplate,代码行数:11,代码来源:test_service.py

示例15: test_server_custom

    def test_server_custom(self, mock_ioloop, mock_parse_args):
        mock_ioloop.time = mock.Mock(return_value=time())
        mock_ioloop.current.return_value = mock_ioloop

        args = mock.MagicMock()
        args.name = "test"
        args.port = get_unused_port()
        args.settings = "{}"
        args.endpoints = None
        mock_parse_args.return_value = args

        start_server()
开发者ID:gakhov,项目名称:api.boilerplate,代码行数:12,代码来源:test_service.py


注:本文中的tornado.testing.get_unused_port函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。