- 更新 openspec/config.yaml 中 git 任务相关说明 - 将 scripts.core.* 改为 core.*,scripts.readers.* 改为 readers.* - 优化 lyxy_document_reader.py 中 sys.path 设置方式 - 同步更新所有测试文件的导入路径
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""测试所有 HTML Readers 的一致性。"""
|
|
|
|
import pytest
|
|
from readers.html import (
|
|
html2text,
|
|
markitdown,
|
|
trafilatura,
|
|
domscribe,
|
|
)
|
|
|
|
|
|
class TestHtmlReadersConsistency:
|
|
"""验证所有 HTML Readers 解析同一文件时核心文字内容一致。"""
|
|
|
|
def test_all_readers_parse_same_content(self, temp_html):
|
|
"""测试所有 Readers 解析同一文件时核心内容一致。"""
|
|
file_path = temp_html(content="""
|
|
<html>
|
|
<head><title>测试页面</title></head>
|
|
<body>
|
|
<h1>测试标题</h1>
|
|
<p>这是测试段落内容。</p>
|
|
<p>第二段内容。</p>
|
|
</body>
|
|
</html>
|
|
""")
|
|
|
|
parsers = [
|
|
("html2text", html2text.parse),
|
|
("markitdown", markitdown.parse),
|
|
("trafilatura", trafilatura.parse),
|
|
("domscribe", domscribe.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 = ["测试标题", "测试段落", "内容", "第二段"]
|
|
for name, content in successful_results:
|
|
assert any(text in content for text in core_texts), \
|
|
f"{name} 解析结果不包含核心内容"
|