Moler Python 编写真的自动化测试工具包 项目简介
Moler 是为构建自动化测试提供“砖块”的 Python 库。 所有这些“砖头”都有明确的责任,有类似的API,遵循相同的构造模式(所以很容易创建新的测试)。功能:命令作为自我依赖的对象 允许封装在单个对象中的命令触发和解析(降低维护成本) 事件监听和回调 (alarms are events example) 允许在线反应(不离线后处理) 后台运行观察者和命令 允许将测试逻辑分解为并行运行的多个命令 允许处理意外的系统行为(重启,警报) 状态机 -> 连接断开后自动重连 增加框架自动恢复并帮助排除“出了什么问题” 自动记录测试使用的设备的所有连接 通过将日志集中在被测系统的不同部分来减少调查时间 使用示例:查找所有python进程的PIDfrom moler.config import load_config
from moler.device.device import DeviceFactory
load_config(config='my_devices.yml') # description of available devices
my_unix = DeviceFactory.get_device(name='MyMachine') # take specific device out of available ones
ps_cmd = my_unix.get_cmd(cmd_name="ps", # take command of that device
cmd_params={"options": "-ef"})
processes_info = ps_cmd() # run the command, it returns result
for proc_info in processes_info:
if 'python' in proc_info['CMD']:
print("PID: {info[PID]} CMD: {info[CMD]}".format(info=proc_info))上述代码执行结果:PID: 1817 CMD: /usr/bin/python /usr/share/system-config-printer/applet.py
PID: 21825 CMD: /usr/bin/python /home/gl/moler/examples/command/unix_ps.py
from moler.device.device import DeviceFactory
load_config(config='my_devices.yml') # description of available devices
my_unix = DeviceFactory.get_device(name='MyMachine') # take specific device out of available ones
ps_cmd = my_unix.get_cmd(cmd_name="ps", # take command of that device
cmd_params={"options": "-ef"})
processes_info = ps_cmd() # run the command, it returns result
for proc_info in processes_info:
if 'python' in proc_info['CMD']:
print("PID: {info[PID]} CMD: {info[CMD]}".format(info=proc_info))上述代码执行结果:PID: 1817 CMD: /usr/bin/python /usr/share/system-config-printer/applet.py
PID: 21825 CMD: /usr/bin/python /home/gl/moler/examples/command/unix_ps.py