"""测试所有 PDF Readers 的一致性。""" import pytest from readers.pdf import ( docling, docling_ocr, markitdown, pypdf, unstructured, unstructured_ocr, ) class TestPdfReadersConsistency: """验证所有 PDF Readers 解析同一文件时核心文字内容一致。""" def test_all_readers_parse_same_content(self, temp_pdf): """测试所有 Readers 解析同一文件时核心内容一致。""" file_path = temp_pdf(text="测试PDF标题\n这是测试段落内容。\n第二段内容。") parsers = [ ("docling", docling.parse), ("docling_ocr", docling_ocr.parse), ("markitdown", markitdown.parse), ("pypdf", pypdf.parse), ("unstructured", unstructured.parse), ("unstructured_ocr", unstructured_ocr.parse), ] successful_results = [] for name, parser in parsers: content, error = parser(file_path) if content is not None and content.strip(): successful_results.append((name, content)) assert len(successful_results) > 0, "没有任何 reader 成功解析文件" core_texts = ["测试", "PDF", "标题", "段落", "内容"] for name, content in successful_results: assert any(text in content for text in core_texts), \ f"{name} 解析结果不包含核心内容"