- 更新 openspec/config.yaml 中 git 任务相关说明 - 将 scripts.core.* 改为 core.*,scripts.readers.* 改为 readers.* - 优化 lyxy_document_reader.py 中 sys.path 设置方式 - 同步更新所有测试文件的导入路径
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
"""测试 MarkItDown PPTX Reader 的解析功能。"""
|
|
|
|
import pytest
|
|
from readers.pptx import markitdown
|
|
|
|
|
|
class TestMarkitdownPptxReaderParse:
|
|
"""测试 MarkItDown PPTX Reader 的 parse 方法。"""
|
|
|
|
def test_normal_file(self, temp_pptx):
|
|
"""测试正常 PPTX 文件解析。"""
|
|
file_path = temp_pptx(slides=[("标题幻灯片", "幻灯片内容"), ("第二页", "第二页内容")])
|
|
content, error = markitdown.parse(file_path)
|
|
if content is not None:
|
|
assert "标题" in content or "幻灯片" in content or "内容" in content
|
|
|
|
def test_file_not_exists(self, tmp_path):
|
|
"""测试文件不存在的情况。"""
|
|
non_existent_file = str(tmp_path / "non_existent.pptx")
|
|
content, error = markitdown.parse(non_existent_file)
|
|
assert content is None
|
|
assert error is not None
|
|
|
|
def test_empty_file(self, temp_pptx):
|
|
"""测试空 PPTX 文件。"""
|
|
file_path = temp_pptx()
|
|
content, error = markitdown.parse(file_path)
|
|
assert content is None or content.strip() == ""
|
|
|
|
def test_corrupted_file(self, temp_pptx, tmp_path):
|
|
"""测试损坏的 PPTX 文件。"""
|
|
file_path = temp_pptx(slides=[("测试", "内容")])
|
|
with open(file_path, "wb") as f:
|
|
f.write(b"corrupted content")
|
|
content, error = markitdown.parse(file_path)
|
|
# MarkItDown 可能会尝试解析任何内容
|
|
assert content is not None or error is not None
|
|
|
|
def test_special_chars(self, temp_pptx):
|
|
"""测试特殊字符处理。"""
|
|
file_path = temp_pptx(slides=[("中文标题 😀", "特殊符号 ©®")])
|
|
content, error = markitdown.parse(file_path)
|
|
if content is not None:
|
|
assert "中文" in content or "标题" in content
|