feat: RapidOCR default OCR engine, office-only ocr_engine, drop operator toggle
ci / smoke (push) Canceled after 0s
ci / smoke (push) Canceled after 0s
This commit is contained in:
1 parent
080237ad3b
commit
fbba169507
16 files changed
+137
-112
No files matched your search
@@ -49,7 +49,7 @@ def test_do_block_and_batch_default_mode(repo_config_path):
|
||||
assert cfg.do.photo_dir == "do_photos"
|
||||
assert cfg.do.max_photos_per_batch == 8
|
||||
assert cfg.do.zone_warn_seconds == 3
|
||||
assert cfg.do.ocr.engine == "tesseract"
|
||||
assert cfg.do.ocr.engine == "rapid"
|
||||
|
||||
|
||||
def test_do_block_missing_uses_defaults(tmp_path):
|
||||
@@ -65,7 +65,7 @@ def test_do_block_missing_uses_defaults(tmp_path):
|
||||
cfg = load_config(p)
|
||||
assert cfg.batch.default_mode == "auto"
|
||||
assert cfg.do.enabled is True
|
||||
assert cfg.do.ocr.engine == "tesseract"
|
||||
assert cfg.do.ocr.engine == "rapid"
|
||||
assert cfg.do.retention_days == 7
|
||||
|
||||
|
||||
|
||||
+23
-6
@@ -116,6 +116,7 @@ def test_ocr_engine_validation():
|
||||
for e in OCR_ENGINES:
|
||||
assert is_valid_ocr_engine(e)
|
||||
assert not is_valid_ocr_engine("easyocr")
|
||||
assert OCR_ENGINES[0] == "rapid" # default engine
|
||||
|
||||
|
||||
def test_empty_do_settings_defaults():
|
||||
@@ -123,7 +124,7 @@ def test_empty_do_settings_defaults():
|
||||
assert s["ocr_engine"] == "tesseract"
|
||||
assert s["require_do"] is True
|
||||
bad = empty_do_settings({"ocr_engine": "nope"})
|
||||
assert bad["ocr_engine"] == "tesseract"
|
||||
assert bad["ocr_engine"] == "rapid"
|
||||
|
||||
|
||||
def test_parse_fields_from_text():
|
||||
@@ -145,6 +146,21 @@ def test_extract_do_fields_none_engine(tmp_path):
|
||||
assert out["engine"] == "none"
|
||||
|
||||
|
||||
def test_extract_do_fields_rapid_engine(tmp_path):
|
||||
from src.do_ocr import extract_do_fields
|
||||
Image = pytest.importorskip("PIL.Image")
|
||||
|
||||
p = tmp_path / "do.png"
|
||||
Image.new("RGB", (200, 60), "white").save(p)
|
||||
out = extract_do_fields(str(p), engine="rapid")
|
||||
assert out["engine"] == "rapid"
|
||||
if out["ocr_ok"]:
|
||||
assert out["ocr_text"] == "" # blank image → empty text, no crash
|
||||
else:
|
||||
# rapid missing → explicit error (never silent fallback)
|
||||
assert "rapidocr" in out["ocr_error"].lower()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Flask API auth tests — skipped when flask/openpyxl not installed (CI)
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -213,17 +229,18 @@ def test_model_mode_post_operator_403(dash_client):
|
||||
assert res.status_code == 403
|
||||
|
||||
|
||||
def test_ocr_engine_post_both_ports(dash_client):
|
||||
def test_ocr_engine_post_office_only(dash_client):
|
||||
client, _, _, settings_path = dash_client
|
||||
res = client.post("/api/do/settings", json={"ocr_engine": "paddle"},
|
||||
headers={"Host": "localhost:5000"})
|
||||
assert res.status_code == 403
|
||||
office = {"Host": f"localhost:{cd_office_port()}"}
|
||||
res = client.post("/api/do/settings", json={"ocr_engine": "paddle"}, headers=office)
|
||||
assert res.status_code == 200
|
||||
assert res.get_json()["ocr_engine"] == "paddle"
|
||||
res = client.post("/api/do/settings", json={"ocr_engine": "tesseract"},
|
||||
headers={"Host": f"localhost:{cd_office_port()}"})
|
||||
res = client.post("/api/do/settings", json={"ocr_engine": "tesseract"}, headers=office)
|
||||
assert res.status_code == 200
|
||||
res = client.post("/api/do/settings", json={"ocr_engine": "bogus"},
|
||||
headers={"Host": "localhost:5000"})
|
||||
res = client.post("/api/do/settings", json={"ocr_engine": "bogus"}, headers=office)
|
||||
assert res.status_code == 400
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user