PaddleOCR-VL-1.6_Demo/tests/test_pdf_text.py

40 lines
1000 B
Python

from ocr_app.pdf_text import TextLayerPolicy, assess_text_layer, normalize_text
def test_normalize_text():
assert normalize_text("a b\r\n\r\n\r\nc") == "a b\n\nc"
def test_usable_text_layer():
text = "有效电子文档内容 123 " * 20
result = assess_text_layer(
text,
width_points=595,
height_points=842,
policy=TextLayerPolicy(),
)
assert result.usable
assert result.reason == "usable_text_layer"
def test_empty_text_layer_routes_to_ocr():
result = assess_text_layer(
"",
width_points=595,
height_points=842,
policy=TextLayerPolicy(),
)
assert not result.usable
assert result.reason == "empty_text_layer"
def test_short_text_layer_routes_to_ocr():
result = assess_text_layer(
"页码 1",
width_points=595,
height_points=842,
policy=TextLayerPolicy(min_chars=50),
)
assert not result.usable
assert result.reason == "too_few_characters"