OCR 省钱三件套:结果缓存、按月预算、跳过无谓裁剪;bench 支持 --skip-done/--no-api
This commit is contained in:
@@ -132,3 +132,45 @@ class ScanFlowTest(unittest.TestCase):
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class NoWastefulCropTest(unittest.TestCase):
|
||||
"""整页读得够好的块,不该再花钱裁出来识别第二次。"""
|
||||
|
||||
def test_complete_block_skips_crop(self):
|
||||
from backend import scanflow
|
||||
|
||||
block = {"i": 0, "box": {"x": 10, "y": 10, "w": 300, "h": 200},
|
||||
"stem": "小明有 12 个苹果,给了小红 5 个,还剩多少个?",
|
||||
"judge_type": "manual", "options": None, "page_answer": "", "subs": []}
|
||||
with mock.patch("backend.tencent_ocr.split_questions") as sp:
|
||||
r = scanflow.recognize_block(Path("data/bench/raw/x.jpg"), block)
|
||||
sp.assert_not_called()
|
||||
self.assertEqual(r["source"], "page")
|
||||
self.assertIn("苹果", r["stem"])
|
||||
|
||||
def test_broken_block_still_crops(self):
|
||||
from backend import scanflow
|
||||
|
||||
block = {"i": 0, "box": {"x": 10, "y": 10, "w": 300, "h": 200},
|
||||
"stem": "1、", "judge_type": "manual", "options": None,
|
||||
"page_answer": "", "subs": []}
|
||||
with mock.patch("backend.scanflow._crop_bytes", return_value=b"jpg"), \
|
||||
mock.patch("backend.tencent_ocr.split_questions",
|
||||
return_value={"ok": True, "questions": [
|
||||
{"stem": "1、6+5-10=", "judge_type": "calc", "options": None,
|
||||
"answer": "1", "page_answer": "", "subs": []}]}) as sp:
|
||||
r = scanflow.recognize_block(Path("data/bench/raw/x.jpg"), block)
|
||||
sp.assert_called_once()
|
||||
self.assertEqual(r["source"], "crop")
|
||||
|
||||
def test_card_block_skips_crop(self):
|
||||
from backend import scanflow
|
||||
|
||||
block = {"i": 0, "box": {"x": 1, "y": 1, "w": 300, "h": 300}, "stem": "10-6= 7+8=",
|
||||
"judge_type": "card", "options": None, "page_answer": "",
|
||||
"subs": [{"stem": "10-6 =", "answer": "4"}]}
|
||||
with mock.patch("backend.tencent_ocr.split_questions") as sp:
|
||||
r = scanflow.recognize_block(Path("data/bench/raw/x.jpg"), block)
|
||||
sp.assert_not_called()
|
||||
self.assertEqual(len(r["subs"]), 1)
|
||||
|
||||
Reference in New Issue
Block a user