feat: 添加 doc/xls/ppt 旧格式文档支持
- 新增 DocReader,支持 markitdown 和 pypandoc-binary 解析器 - 新增 XlsReader,支持 unstructured、markitdown 和 pandas+xlrd 解析器 - 新增 PptReader,支持 markitdown 解析器 - 添加 olefile 依赖用于验证 OLE2 格式 - 更新 config.py 添加 doc/xls/ppt 依赖配置 - 更新 --advice 支持 doc/xls/ppt 格式 - 添加相应的测试用例 - 同步 specs 到主目录
This commit is contained in:
@@ -38,6 +38,27 @@ class TestCLIAdviceOption:
|
||||
output = stdout + stderr
|
||||
assert "无法识别" in output or "错误" in output
|
||||
|
||||
def test_advice_option_doc(self, cli_runner):
|
||||
"""测试 --advice 选项对 DOC 文件。"""
|
||||
stdout, stderr, exit_code = cli_runner(["test.doc", "--advice"])
|
||||
|
||||
assert exit_code == 0
|
||||
assert "文件类型: DOC" in stdout
|
||||
|
||||
def test_advice_option_xls(self, cli_runner):
|
||||
"""测试 --advice 选项对 XLS 文件。"""
|
||||
stdout, stderr, exit_code = cli_runner(["test.xls", "--advice"])
|
||||
|
||||
assert exit_code == 0
|
||||
assert "文件类型: XLS" in stdout
|
||||
|
||||
def test_advice_option_ppt(self, cli_runner):
|
||||
"""测试 --advice 选项对 PPT 文件。"""
|
||||
stdout, stderr, exit_code = cli_runner(["test.ppt", "--advice"])
|
||||
|
||||
assert exit_code == 0
|
||||
assert "文件类型: PPT" in stdout
|
||||
|
||||
|
||||
class TestCLIDefaultOutput:
|
||||
"""测试 CLI 默认输出功能。"""
|
||||
|
||||
1
tests/test_readers/test_doc/__init__.py
Normal file
1
tests/test_readers/test_doc/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""测试 DocReader 模块。"""
|
||||
21
tests/test_readers/test_doc/test_consistency.py
Normal file
21
tests/test_readers/test_doc/test_consistency.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""测试所有 DOC Readers 的一致性。"""
|
||||
|
||||
import pytest
|
||||
from readers.doc import markitdown, pypandoc
|
||||
|
||||
|
||||
class TestDocReadersConsistency:
|
||||
"""验证 DOC Readers 模块结构正确。"""
|
||||
|
||||
def test_parsers_importable(self):
|
||||
"""测试所有 parser 模块可以正确导入。"""
|
||||
# 验证模块导入成功
|
||||
assert markitdown is not None
|
||||
assert pypandoc is not None
|
||||
assert hasattr(markitdown, 'parse')
|
||||
assert hasattr(pypandoc, 'parse')
|
||||
|
||||
def test_parser_functions_callable(self):
|
||||
"""测试 parse 函数是可调用的。"""
|
||||
assert callable(markitdown.parse)
|
||||
assert callable(pypandoc.parse)
|
||||
25
tests/test_readers/test_doc/test_markitdown_doc.py
Normal file
25
tests/test_readers/test_doc/test_markitdown_doc.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""测试 MarkItDown DOC Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from readers.doc import markitdown
|
||||
|
||||
|
||||
class TestMarkitdownDocReaderParse:
|
||||
"""测试 MarkItDown DOC Reader 的 parse 方法。"""
|
||||
|
||||
def test_module_importable(self):
|
||||
"""测试模块可以正确导入。"""
|
||||
assert markitdown is not None
|
||||
assert hasattr(markitdown, 'parse')
|
||||
assert callable(markitdown.parse)
|
||||
|
||||
def test_file_not_exists(self, tmp_path):
|
||||
"""测试文件不存在的情况。"""
|
||||
non_existent_file = str(tmp_path / "non_existent.doc")
|
||||
|
||||
content, error = markitdown.parse(non_existent_file)
|
||||
|
||||
# 验证返回 None 和错误信息
|
||||
assert content is None
|
||||
assert error is not None
|
||||
25
tests/test_readers/test_doc/test_pypandoc_doc.py
Normal file
25
tests/test_readers/test_doc/test_pypandoc_doc.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""测试 pypandoc DOC Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from readers.doc import pypandoc
|
||||
|
||||
|
||||
class TestPypandocDocReaderParse:
|
||||
"""测试 pypandoc DOC Reader 的 parse 方法。"""
|
||||
|
||||
def test_module_importable(self):
|
||||
"""测试模块可以正确导入。"""
|
||||
assert pypandoc is not None
|
||||
assert hasattr(pypandoc, 'parse')
|
||||
assert callable(pypandoc.parse)
|
||||
|
||||
def test_file_not_exists(self, tmp_path):
|
||||
"""测试文件不存在的情况。"""
|
||||
non_existent_file = str(tmp_path / "non_existent.doc")
|
||||
|
||||
content, error = pypandoc.parse(non_existent_file)
|
||||
|
||||
# 验证返回 None 和错误信息
|
||||
assert content is None
|
||||
assert error is not None
|
||||
1
tests/test_readers/test_ppt/__init__.py
Normal file
1
tests/test_readers/test_ppt/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""测试 PptReader 模块。"""
|
||||
18
tests/test_readers/test_ppt/test_consistency.py
Normal file
18
tests/test_readers/test_ppt/test_consistency.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""测试所有 PPT Readers 的一致性。"""
|
||||
|
||||
import pytest
|
||||
from readers.ppt import markitdown
|
||||
|
||||
|
||||
class TestPptReadersConsistency:
|
||||
"""验证 PPT Readers 模块结构正确。"""
|
||||
|
||||
def test_parsers_importable(self):
|
||||
"""测试所有 parser 模块可以正确导入。"""
|
||||
# 验证模块导入成功
|
||||
assert markitdown is not None
|
||||
assert hasattr(markitdown, 'parse')
|
||||
|
||||
def test_parser_functions_callable(self):
|
||||
"""测试 parse 函数是可调用的。"""
|
||||
assert callable(markitdown.parse)
|
||||
25
tests/test_readers/test_ppt/test_markitdown_ppt.py
Normal file
25
tests/test_readers/test_ppt/test_markitdown_ppt.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""测试 MarkItDown PPT Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from readers.ppt import markitdown
|
||||
|
||||
|
||||
class TestMarkitdownPptReaderParse:
|
||||
"""测试 MarkItDown PPT Reader 的 parse 方法。"""
|
||||
|
||||
def test_module_importable(self):
|
||||
"""测试模块可以正确导入。"""
|
||||
assert markitdown is not None
|
||||
assert hasattr(markitdown, 'parse')
|
||||
assert callable(markitdown.parse)
|
||||
|
||||
def test_file_not_exists(self, tmp_path):
|
||||
"""测试文件不存在的情况。"""
|
||||
non_existent_file = str(tmp_path / "non_existent.ppt")
|
||||
|
||||
content, error = markitdown.parse(non_existent_file)
|
||||
|
||||
# 验证返回 None 和错误信息
|
||||
assert content is None
|
||||
assert error is not None
|
||||
1
tests/test_readers/test_xls/__init__.py
Normal file
1
tests/test_readers/test_xls/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""测试 XlsReader 模块。"""
|
||||
24
tests/test_readers/test_xls/test_consistency.py
Normal file
24
tests/test_readers/test_xls/test_consistency.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""测试所有 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)
|
||||
25
tests/test_readers/test_xls/test_markitdown_xls.py
Normal file
25
tests/test_readers/test_xls/test_markitdown_xls.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""测试 MarkItDown XLS Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from readers.xls import markitdown
|
||||
|
||||
|
||||
class TestMarkitdownXlsReaderParse:
|
||||
"""测试 MarkItDown XLS Reader 的 parse 方法。"""
|
||||
|
||||
def test_module_importable(self):
|
||||
"""测试模块可以正确导入。"""
|
||||
assert markitdown is not None
|
||||
assert hasattr(markitdown, 'parse')
|
||||
assert callable(markitdown.parse)
|
||||
|
||||
def test_file_not_exists(self, tmp_path):
|
||||
"""测试文件不存在的情况。"""
|
||||
non_existent_file = str(tmp_path / "non_existent.xls")
|
||||
|
||||
content, error = markitdown.parse(non_existent_file)
|
||||
|
||||
# 验证返回 None 和错误信息
|
||||
assert content is None
|
||||
assert error is not None
|
||||
25
tests/test_readers/test_xls/test_pandas_xls.py
Normal file
25
tests/test_readers/test_xls/test_pandas_xls.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""测试 pandas XLS Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from readers.xls import pandas
|
||||
|
||||
|
||||
class TestPandasXlsReaderParse:
|
||||
"""测试 pandas XLS Reader 的 parse 方法。"""
|
||||
|
||||
def test_module_importable(self):
|
||||
"""测试模块可以正确导入。"""
|
||||
assert pandas is not None
|
||||
assert hasattr(pandas, 'parse')
|
||||
assert callable(pandas.parse)
|
||||
|
||||
def test_file_not_exists(self, tmp_path):
|
||||
"""测试文件不存在的情况。"""
|
||||
non_existent_file = str(tmp_path / "non_existent.xls")
|
||||
|
||||
content, error = pandas.parse(non_existent_file)
|
||||
|
||||
# 验证返回 None 和错误信息
|
||||
assert content is None
|
||||
assert error is not None
|
||||
25
tests/test_readers/test_xls/test_unstructured_xls.py
Normal file
25
tests/test_readers/test_xls/test_unstructured_xls.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""测试 unstructured XLS Reader 的解析功能。"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
from readers.xls import unstructured
|
||||
|
||||
|
||||
class TestUnstructuredXlsReaderParse:
|
||||
"""测试 unstructured XLS Reader 的 parse 方法。"""
|
||||
|
||||
def test_module_importable(self):
|
||||
"""测试模块可以正确导入。"""
|
||||
assert unstructured is not None
|
||||
assert hasattr(unstructured, 'parse')
|
||||
assert callable(unstructured.parse)
|
||||
|
||||
def test_file_not_exists(self, tmp_path):
|
||||
"""测试文件不存在的情况。"""
|
||||
non_existent_file = str(tmp_path / "non_existent.xls")
|
||||
|
||||
content, error = unstructured.parse(non_existent_file)
|
||||
|
||||
# 验证返回 None 和错误信息
|
||||
assert content is None
|
||||
assert error is not None
|
||||
Reference in New Issue
Block a user