test: 验证 Python stdin/stdout JSON 通信

This commit is contained in:
MikiVL 2026-05-05 13:19:20 +08:00
parent 7ca81403e0
commit 8fe2d2bb88

24
tests/python/test_main.py Normal file
View File

@ -0,0 +1,24 @@
import sys, os, json, subprocess
PYTHON = sys.executable
MAIN = os.path.join(os.path.dirname(__file__), "../../python/main.py")
FIXTURE = os.path.join(os.path.dirname(__file__), "../fixtures/sample_template.xlsx")
def _call(payload: dict) -> dict:
proc = subprocess.run(
[PYTHON, MAIN],
input=json.dumps(payload) + "\n",
capture_output=True,
text=True,
timeout=10,
)
return json.loads(proc.stdout.strip())
def test_parse_template_via_stdin():
result = _call({"action": "parse_template", "file_path": FIXTURE})
assert "sheets" in result
assert "Sheet1" in result["sheets"]
def test_unknown_action_returns_error():
result = _call({"action": "nonexistent"})
assert "error" in result