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、时间戳等
Metadata
Release files for autestoy 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| autestoy-0.1.6.tar.gz | 58.8 kB | Without provenance | Details for autestoy-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| autestoy-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for autestoy-0.1.6-py3-none-any.whl |
Total release size: 124.8 kB
Release files / autestoy-0.1.6.tar.gz
| Download URL | autestoy-0.1.6.tar.gz |
|---|---|
| Size | 58.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
710cef38a93de308c44401b2496f855d24cff94dded0337363b925d076dbbe28
|
|
BLAKE2b-256 checksum How to use checksums |
35279db52c62ed587362fd42f8ece6a89b2f60a496f5adb6a7a0a59fbb3093dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / autestoy-0.1.6-py3-none-any.whl
| Download URL | autestoy-0.1.6-py3-none-any.whl |
|---|---|
| Size | 66.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf43cb9d4af46cac7a7380791c4ca8f3addf87b34f9c2a368225a0594d7edb4a
|
|
BLAKE2b-256 checksum How to use checksums |
f0e656e38a446407888b582d5f9378293f9280e223f91ba54554bad1d16ae5e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for autestoy 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.