从其他规避模块收集的帮助函数,以帮助重用,例如get_free_port()和wait_for_ready()。
evasion-common的Python项目详细描述
内容
Introduction
这个包提供了“规避。普通”。这是一组有用的函数 以及其他公用事业。
evasion.common.net
get_free_port
在本地查找未使用的TCP端口并将其返回这会发现一个随机的 端口在2000-10000之间它通过绑定来测试是否可用。它 关闭套接字并返回端口。
这对于在接受时获得运行服务的免费端口非常方便 测试。
示例用法:
from evasion.common import net # Get a free port: port1 = net.get_free_port() # Get another free port excluding the first port from the list port1 = net.get_free_port(exclude_ports=[port1])
wait_for_ready
调用以等待web应用程序响应正常请求这是 当你想知道一个web应用不仅仅是绑定到一个套接字,而是 实际上对根页面下载响应200 OK。
单元测试中的示例用法:
from evasion.common import net from evasion.common import webhelpers port1 = net.get_free_port() # Run the web app and wait for ready should connect: web = webhelpers.BasicWeb(port=port1) web.start() result = net.wait_for_ready(web.uri) assert result web.stop()
wait_for_service
调用以等待与远程服务建立套接字连接
单元测试的示例用法:
from evasion.common import net from evasion.common import webhelpers port1 = net.get_free_port() # Run the web app and wait for ready should connect: web = webhelpers.BasicWeb(port=port1) web.start() result = net.wait_for_service('localhost', port1) assert result web.stop()