fix: pybot 审计修复——插件异常类型、I2C 引用校验、卡尔曼除零守卫、CLI 端到端测试

This commit is contained in:
qing committed 2026-08-10 16:16:40 +00:00
1 parent 09dc36d591
commit a8ffa73a6b
6 files changed
+70 -6

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
"""CLI 端到端测试:--dry-run / --test roundtrip / stdin 输入"""
import io
import sys
from tests.conftest import SCRIPTS_DIR
from pybot.main import main
def test_stdin_input(monkeypatch):
"""stdin 输入(模拟 cat script | pybot)"""
src = (SCRIPTS_DIR / "std.mt").read_text(encoding="utf-8")
monkeypatch.setattr(sys, "stdin", io.StringIO(src))
monkeypatch.setattr(sys, "argv", ["pybot", "--dry-run"])
# 验证不抛异常且返回 0
assert main(["--dry-run"]) == 0
def test_cli_help():
"""--help 返回 0"""
try:
main(["--help"])
except SystemExit as e:
assert e.code == 0
def test_test_roundtrip(tmp_path):
"""--test roundtrip in.mt out.mt 往返"""
src = (SCRIPTS_DIR / "std.mt").read_text(encoding="utf-8")
infile = tmp_path / "in.mt"
infile.write_text(src, encoding="utf-8")
outfile = tmp_path / "out.mt"
assert main(["--test", "roundtrip", str(infile), str(outfile)]) == 0
# 输出可被再次解析
from pybot.parser import MatrixParser
parser = MatrixParser(outfile.read_text(encoding="utf-8"))
blocks = []
while True:
obj = parser.parse()
if obj is None:
break
blocks.append(obj)
assert len(blocks) == 7 # std.mt 含 7 个 @块
def test_test_unknown_mode():
"""未知 --test 模式返回 2"""
assert main(["--test", "unknown", "/dev/null", "/dev/null"]) == 2