• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python testing.get_unused_port函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: get_app

    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)

        config.update({"BACKENDS": {"gottwall.backends.tcpip.TCPIPBackend": {
            "PORT": get_unused_port()}},
            "STORAGE": "gottwall.storages.MemoryStorage",
            "PROJECTS": {"test_project": "secretkey"},
            "PRIVATE_KEY": "myprivatekey"})
        self.app = AggregatorApplication(config)
        self.app.configure_app(self.io_loop)

        return self.app
开发者ID:GottWall,项目名称:GottWall,代码行数:13,代码来源:backends.py


示例17: get_app

    def get_app(self):
        config = Config()
        config.from_module(gottwall.default_config)
        config.update({"BACKENDS": {
            "gottwall.backends.http.HTTPBackend": {
                "PORT": get_unused_port()}
            },
            "PROJECTS": {"test_project": "secretkey"},
            "SECRET_KEY": "myprivatekey"})
        self.app = AggregatorApplication(config)
        self.app.configure_app(self.io_loop)

        return self.app
开发者ID:Lispython,项目名称:GottWall,代码行数:13,代码来源:backends.py


示例18: test_connection_refused

 def test_connection_refused(self):
     # When a connection is refused, the connect callback should not
     # be run.  (The kqueue IOLoop used to behave differently from the
     # epoll IOLoop in this respect)
     port = get_unused_port()
     stream = IOStream(socket.socket(), self.io_loop)
     self.connect_called = False
     def connect_callback():
         self.connect_called = True
     stream.set_close_callback(self.stop)
     stream.connect(("localhost", port), connect_callback)
     self.wait()
     self.assertFalse(self.connect_called)
开发者ID:ChainBoy,项目名称:WorkFile-Sonidigg,代码行数:13,代码来源:iostream_test.py


示例19: test_connect_timeout

    def test_connect_timeout(self):
        # create a socket and bind it to a port, but don't
        # call accept so the connection will timeout.
        #get_unused_port()
        port = get_unused_port()

        with closing(socket.socket()) as sock:
            sock.bind(('', port))
            self.http_client.fetch("http://localhost:%d/" % port,
                                   self.stop,
                                   connect_timeout=0.1)
            response = self.wait()
            self.assertEqual(response.code, 599)
            self.assertEqual(str(response.error), "HTTP 599: Timeout")
开发者ID:rehmetjan,项目名称:tornado,代码行数:14,代码来源:simple_httpclient_test.py


示例20: test_connection_refused

    def test_connection_refused(self):
        port = get_unused_port()
        self.http_client.fetch("http://localhost:%d/" % port, self.stop)
        response = self.wait()
        self.assertEqual(599, response.code)

        if sys.platform != 'cygwin':
            # cygwin returns EPERM instead of ECONNREFUSED here
            self.assertTrue(str(errno.ECONNREFUSED) in str(response.error),
                            response.error)
            # This is usually "Connection refused".
            # On windows, strerror is broken and returns "Unknown error".
            expected_message = os.strerror(errno.ECONNREFUSED)
            self.assertTrue(expected_message in str(response.error),
                            response.error)
开发者ID:mega85,项目名称:tornado,代码行数:15,代码来源:simple_httpclient_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.AsyncHTTPSTestCase类代码示例发布时间:2022-05-27
下一篇:
Python testing.bind_unused_port函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap