"""测试所有 XLS Readers 的一致性。""" import pytest from readers.xls import unstructured, markitdown, pandas class TestXlsReadersConsistency: """验证所有 XLS Readers 解析同一文件时核心文字内容一致。""" def test_parsers_importable(self): """测试所有 parser 模块可以正确导入。""" # 验证模块导入成功 assert unstructured is not None assert markitdown is not None assert pandas is not None assert hasattr(unstructured, 'parse') assert hasattr(markitdown, 'parse') assert hasattr(pandas, 'parse') def test_parser_functions_callable(self): """测试 parse 函数是可调用的。""" assert callable(unstructured.parse) assert callable(markitdown.parse) assert callable(pandas.parse) def test_all_readers_parse_same_content(self, simple_xls_path): """测试所有 Readers 解析同一文件时核心内容一致。""" # 收集所有 readers 的解析结果 parsers = [ ("unstructured", unstructured.parse), ("markitdown", markitdown.parse), ("pandas", pandas.parse), ] successful_results = [] for name, parser in parsers: content, error = parser(simple_xls_path) if content is not None and content.strip(): successful_results.append((name, content)) # 至少应该有一个 reader 成功解析,或者都不解析也可以 if len(successful_results) > 0: # 验证所有成功的 readers 都包含核心内容 core_texts = ["姓名", "年龄", "城市", "张三", "李四"] for name, content in successful_results: # 至少包含一个核心文本 assert any(text in content for text in core_texts), \ f"{name} 解析结果不包含核心内容"