本文整理汇总了Python中aiohttp.test_utils.unused_port方法的典型用法代码示例。如果您正苦于以下问题:Python test_utils.unused_port方法的具体用法?Python test_utils.unused_port怎么用?Python test_utils.unused_port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.test_utils
的用法示例。
在下文中一共展示了test_utils.unused_port方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import unused_port [as 别名]
def __init__(self, *, side_effect=None, loop):
self.loop = loop
if side_effect is None:
side_effect = {
'status': 200,
}
self._side_effect = side_effect
self._slop_factor = 0
self.app = web.Application(loop=loop)
self.setup_routes()
self.port = unused_port()
self.hits = defaultdict(lambda: 0)
示例2: run
# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import unused_port [as 别名]
def run(target: Callable, port: Optional[int] = None, timeout: float = 0.05, **kwargs: Any) -> int:
"""Start a thread with the given aiohttp application."""
if port is None:
port = unused_port()
server_thread = threading.Thread(target=target, kwargs={"port": port, **kwargs})
server_thread.daemon = True
server_thread.start()
sleep(timeout)
return port
示例3: __init__
# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import unused_port [as 别名]
def __init__(self, loop, write_buff):
self._loop = loop
self._write_buff = write_buff
self._transports = []
self._srv = None
self.port = unused_port()
示例4: setUp
# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import unused_port [as 别名]
def setUp(self):
self.message_results = []
self.port = unused_port()
self.session = None
self.transport = WsTransport("0.0.0.0", self.port, self.create_session)
self.transport.wire_format = JsonWireFormat()
self.result_event = None
super(TestWsTransport, self).setUp()
示例5: setUp
# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import unused_port [as 别名]
def setUp(self):
self.message_results = []
self.port = unused_port()
self.session = None
self.transport = HttpTransport(
"0.0.0.0", self.port, self.create_session, max_message_size=65535
)
self.transport.wire_format = JsonWireFormat()
self.result_event = None
self.response_message = None
super(TestHttpTransport, self).setUp()
示例6: start
# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import unused_port [as 别名]
def start(self):
port = unused_port()
self.runner = web.AppRunner(self.app)
await self.runner.setup()
site = web.TCPSite(self.runner, '127.0.0.1', port,
ssl_context=self.ssl_context)
await site.start()
return {'www.cloudflare.com': port}
示例7: __init__
# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import unused_port [as 别名]
def __init__(self):
self.host = 'localhost'
self.port = unused_port()
self.app = web.Application()
self.app.router.add_route(method='POST',
path='/{path:.*}',
handler=self.handle_POST)
self.handler = None
self.server = None
self.response = None
self.requests = []
self.auth = None
示例8: start
# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import unused_port [as 别名]
def start(self):
self.port = port = unused_port()
self.runner = web.AppRunner(self.app)
await self.runner.setup()
site = web.TCPSite(self.runner, '127.0.0.1', port)
await site.start()
return port
示例9: start
# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import unused_port [as 别名]
def start(self):
if self.port is None:
self.port = unused_port()
self.handler = self.app.make_handler()
self.server = await self.loop.create_server(
self.handler, "127.0.0.1", self.port, ssl=self.ssl_context
)
# return the base url and port which need to be resolved/mocked.
resolver = FakeResolver({self.base_url: self.port}, loop=self.loop)
connector = aiohttp.TCPConnector(
loop=self.loop, resolver=resolver, verify_ssl=False
)
return connector