autestoy is a Python toy library for automating tests. autestoy -> auto test toy
Project description
autestoy
auto + test + toy — 面向嵌入式/硬件测试场景的 Python 自动化测试工具库
主要功能
- 多协议远程连接:SSH(含 Channel、SFTP、sudo)、Serial、Telnet
- 本机命令执行:
Local/LocalPopen,接口与远程协议一致 - 类 Verilog 数据类型:
Bits支持位宽字面量、切片、拼接(@)、位运算;BitView视图借用 - 寄存器建模:
Register/Field/RegGroup,快速定义硬件寄存器及位域 - 命令记录:
CmdRecord统一封装执行结果,支持正则搜索、字段提取、fifo 匹配 - 消息总线:
MessageIO发布/订阅模式,解耦命令执行与输出渲染
安装
pip install autestoy
快速上手
SSH
import autestoy as att
conf = att.RemoteConfig(
user="root", host="192.168.1.100", password="xxx"
).set_name("DUT")
with att.SSH(conf) as ssh:
# 执行命令
r = ssh.exec_run("uname -a")
if "Linux" in r:
print("Linux 设备")
# 正则搜索
m = r.search(r"(\d+\.\d+\.\d+)")
print(m.group(1)) # 内核版本
# 批量执行
ssh.exec_run_lines("make clean", "make", "make test")
# 后台长任务 + 实时监控
task = ssh.long_running("tail -f /var/log/app.log")
ssh.exec_run("systemctl restart my-app")
t = att.TrySeconds(10)
while t:
if task.search_next_line(r"error"):
att.ulog("发现异常", att.AnsiColor.red)
break
task.task_kill()
Channel / SFTP
with att.SSH(conf) as ssh:
# 交互式通道(保持目录和环境变量)
with ssh.create_channel("build") as ch:
ch.run("cd /project && export MODE=release")
ch.run("./build.sh")
# 文件传输
sftp = ssh.create_ftp()
sftp.put("local.bin", "/remote/fw.bin")
sftp.get("/remote/log.txt", "./log.txt")
Bits
val = att.Bits("8'd255") # Verilog 风格字面量
val = att.Bits(0x1234, 16) # 整数 + 位宽
low = val[7:0] # 切片读取 : 0x34
val[15:8] = 0xAB # 切片赋值
c = att.Bits(0xFF, 8) @ att.Bits(0x00, 8) # 拼接 : 0xFF00
寄存器定义
from autestoy.tools.register import Field, Register, dataclass
from autestoy.tools.datatype import Bits
@dataclass(slots=True)
class PWR_CTLR(Register):
VOLTAGE = Field(
bit_range=(12, 10), default=Bits(0, 3),
select={Bits(0b000, 3): "1.2V", Bits(0b011, 3): "3.3V"},
R=True, W=True,
)
reg = PWR_CTLR()
print(reg.VOLTAGE.select_str) # 当前电压描述
串口 / Telnet / 本机
ser = att.SerialShell(att.SerialConfig(port="COM3", baudrate=115200))
ser.login(("root", "xxx"))
ser.shell_run("cat /proc/cpuinfo")
with att.Local() as local:
local.exec_run("df -h")
消息总线
from autestoy.export.messageio import MessageDispatcher
from autestoy.export.term import MessageTerminal
disp = MessageDispatcher()
disp.link_line(MessageTerminal()).start()
disp.start()
# ... 正常使用,输出自动路由到终端
disp.join()
项目结构
src/autestoy/
├── __init__.py
├── export/ # 终端输出、消息总线、Markdown 导出
├── protocols/ # SSH、Serial、Telnet、本地执行
└── tools/ # Bits、Register、CmdRecord、ansi、时间戳等
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
autestoy-0.1.6.tar.gz
(58.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
autestoy-0.1.6-py3-none-any.whl
(66.0 kB
view details)
File details
Details for the file autestoy-0.1.6.tar.gz.
File metadata
- Download URL: autestoy-0.1.6.tar.gz
- Upload date:
- Size: 58.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
710cef38a93de308c44401b2496f855d24cff94dded0337363b925d076dbbe28
|
|
| MD5 |
1be73007defc2d81fa467393900da222
|
|
| BLAKE2b-256 |
35279db52c62ed587362fd42f8ece6a89b2f60a496f5adb6a7a0a59fbb3093dc
|
File details
Details for the file autestoy-0.1.6-py3-none-any.whl.
File metadata
- Download URL: autestoy-0.1.6-py3-none-any.whl
- Upload date:
- Size: 66.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf43cb9d4af46cac7a7380791c4ca8f3addf87b34f9c2a368225a0594d7edb4a
|
|
| MD5 |
120b83b88beac40a84cfdbdd23aeeee5
|
|
| BLAKE2b-256 |
f0e656e38a446407888b582d5f9378293f9280e223f91ba54554bad1d16ae5e6
|