feat: 同步报销流程与工作台改动
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import stat
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from app.core.config import get_settings
|
||||
@@ -88,6 +89,46 @@ print("__OCR_JSON__=" + json.dumps(payload, ensure_ascii=False))
|
||||
assert skipped.warnings == ["当前仅支持图片和 PDF 文件进行 OCR。"]
|
||||
|
||||
|
||||
def test_ocr_service_passes_configured_device_to_worker(
|
||||
monkeypatch,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
captured_commands: list[list[str]] = []
|
||||
|
||||
def fake_run(
|
||||
command: list[str],
|
||||
*,
|
||||
capture_output: bool,
|
||||
text: bool,
|
||||
timeout: int,
|
||||
check: bool,
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
captured_commands.append(command)
|
||||
return subprocess.CompletedProcess(
|
||||
args=command,
|
||||
returncode=0,
|
||||
stdout='__OCR_JSON__={"engine":"paddleocr_mobile","model":"PP-OCRv5_mobile","documents":[]}\n',
|
||||
stderr="",
|
||||
)
|
||||
|
||||
monkeypatch.setenv("OCR_DEVICE", "gpu:0")
|
||||
get_settings.cache_clear()
|
||||
monkeypatch.setattr(subprocess, "run", fake_run)
|
||||
try:
|
||||
payload = OcrService()._invoke_worker(
|
||||
python_bin="python",
|
||||
worker_path="worker.py",
|
||||
input_paths=[tmp_path / "invoice.png"],
|
||||
)
|
||||
finally:
|
||||
get_settings.cache_clear()
|
||||
|
||||
assert payload["engine"] == "paddleocr_mobile"
|
||||
command = captured_commands[0]
|
||||
device_index = command.index("--device")
|
||||
assert command[device_index + 1] == "gpu:0"
|
||||
|
||||
|
||||
def test_ocr_service_converts_pdf_to_images_and_returns_image_preview(
|
||||
monkeypatch,
|
||||
tmp_path: Path,
|
||||
|
||||
Reference in New Issue
Block a user