feat: 添加 doc/xls/ppt 旧格式文档静态测试文件支持
- 更新 .gitattributes,将 fixtures 目录所有文件纳入 Git LFS - 在 tests/test_readers/conftest.py 中添加静态文件 fixtures - 添加 doc/xls/ppt 静态测试文件(9个文件) - 更新各旧格式解析器测试用例使用静态文件 - 更新一致性测试使用静态文件 - 在 README.md 中添加 fixtures 使用规范 - 同步 delta specs 到主 specs(doc-reader/xls-reader/ppt-reader/reader-testing/test-fixtures) - 归档 add-static-test-fixtures 变更
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
"Bash(wc:*)",
|
"Bash(wc:*)",
|
||||||
"Bash(curl:*)",
|
"Bash(curl:*)",
|
||||||
"mcp__context7__query-docs",
|
"mcp__context7__query-docs",
|
||||||
|
"mcp__context7__resolve-library-id",
|
||||||
"mcp__exa__web_search_exa",
|
"mcp__exa__web_search_exa",
|
||||||
"mcp__exa__get_code_context_exa"
|
"mcp__exa__get_code_context_exa"
|
||||||
],
|
],
|
||||||
|
|||||||
12
.gitattributes
vendored
12
.gitattributes
vendored
@@ -1,13 +1,3 @@
|
|||||||
# Git LFS 配置
|
# Git LFS 配置
|
||||||
# 追踪大型二进制测试文件
|
# 追踪大型二进制测试文件
|
||||||
# PDF 文件
|
tests/test_readers/fixtures/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
tests/fixtures/documents/**/*.pdf filter=lfs diff=lfs merge=lfs -text
|
|
||||||
# Office 文档(可选,根据需要启用)
|
|
||||||
tests/fixtures/documents/**/*.docx filter=lfs diff=lfs merge=lfs -text
|
|
||||||
tests/fixtures/documents/**/*.xlsx filter=lfs diff=lfs merge=lfs -text
|
|
||||||
tests/fixtures/documents/**/*.pptx filter=lfs diff=lfs merge=lfs -text
|
|
||||||
# 图片文件
|
|
||||||
tests/fixtures/documents/**/*.png filter=lfs diff=lfs merge=lfs -text
|
|
||||||
tests/fixtures/documents/**/*.jpg filter=lfs diff=lfs merge=lfs -text
|
|
||||||
tests/fixtures/documents/**/*.jpeg filter=lfs diff=lfs merge=lfs -text
|
|
||||||
tests/fixtures/documents/**/*.gif filter=lfs diff=lfs merge=lfs -text
|
|
||||||
|
|||||||
55
README.md
55
README.md
@@ -38,11 +38,37 @@ scripts/
|
|||||||
└── encoding_detection.py # 编码检测
|
└── encoding_detection.py # 编码检测
|
||||||
|
|
||||||
tests/ # 测试套件
|
tests/ # 测试套件
|
||||||
|
├── test_readers/ # Reader 测试
|
||||||
|
│ └── fixtures/ # 静态测试文件(Git LFS 管理)
|
||||||
|
│ ├── doc/ # DOC 旧格式测试文件
|
||||||
|
│ ├── xls/ # XLS 旧格式测试文件
|
||||||
|
│ └── ppt/ # PPT 旧格式测试文件
|
||||||
openspec/ # OpenSpec 规范文档
|
openspec/ # OpenSpec 规范文档
|
||||||
README.md # 本文档(开发者文档)
|
README.md # 本文档(开发者文档)
|
||||||
SKILL.md # AI Skill 文档
|
SKILL.md # AI Skill 文档
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 测试 Fixtures 规范
|
||||||
|
|
||||||
|
### 静态测试文件目录
|
||||||
|
|
||||||
|
`tests/test_readers/fixtures/` 目录用于存放**预先准备的静态测试文件**,特别是难以通过 Python 自动化创建的旧格式文件(.doc/.xls/.ppt)。
|
||||||
|
|
||||||
|
### 目录使用规则
|
||||||
|
|
||||||
|
1. **仅存放静态文件**:该目录下的文件必须是预先准备好的,禁止在测试运行时向该目录动态生成临时文件。
|
||||||
|
2. **临时文件使用 tmp_path**:测试中需要临时文件时,使用 pytest 的 `tmp_path` fixture 在其他位置创建。
|
||||||
|
3. **Git LFS 管理**:该目录下所有文件通过 Git LFS 管理,见 `.gitattributes` 配置。
|
||||||
|
|
||||||
|
### Fixture 说明
|
||||||
|
|
||||||
|
`tests/test_readers/conftest.py` 提供以下静态文件 fixtures:
|
||||||
|
|
||||||
|
- 目录路径:`doc_fixture_path`、`xls_fixture_path`、`ppt_fixture_path`
|
||||||
|
- 单个文件:`simple_doc_path`、`with_headings_doc_path`、`with_table_doc_path` 等
|
||||||
|
|
||||||
|
文件不存在时会自动 `pytest.skip()`,保证 CI 稳定性。
|
||||||
|
|
||||||
## 核心概念
|
## 核心概念
|
||||||
|
|
||||||
### Reader 机制
|
### Reader 机制
|
||||||
@@ -198,6 +224,35 @@ uv run \
|
|||||||
pytest tests/test_readers/test_html/
|
pytest tests/test_readers/test_html/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### 测试 DOC reader(旧格式,使用静态文件)
|
||||||
|
```bash
|
||||||
|
uv run \
|
||||||
|
--with pytest \
|
||||||
|
--with "markitdown[docx]" \
|
||||||
|
--with pypandoc-binary \
|
||||||
|
pytest tests/test_readers/test_doc/
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 测试 XLS reader(旧格式,使用静态文件)
|
||||||
|
```bash
|
||||||
|
uv run \
|
||||||
|
--with pytest \
|
||||||
|
--with "unstructured[xlsx]" \
|
||||||
|
--with "markitdown[xls]" \
|
||||||
|
--with pandas \
|
||||||
|
--with tabulate \
|
||||||
|
--with xlrd \
|
||||||
|
pytest tests/test_readers/test_xls/
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 测试 PPT reader(旧格式,使用静态文件)
|
||||||
|
```bash
|
||||||
|
uv run \
|
||||||
|
--with pytest \
|
||||||
|
--with "markitdown[pptx]" \
|
||||||
|
pytest tests/test_readers/test_ppt/
|
||||||
|
```
|
||||||
|
|
||||||
#### 运行特定测试文件或方法
|
#### 运行特定测试文件或方法
|
||||||
```bash
|
```bash
|
||||||
# 运行特定测试文件(CLI 测试无需额外依赖)
|
# 运行特定测试文件(CLI 测试无需额外依赖)
|
||||||
|
|||||||
@@ -51,3 +51,18 @@ DOC 文档解析能力,支持解析 Microsoft Word 97-2003 旧格式文档。
|
|||||||
#### Scenario: pypandoc 解析器在独立文件
|
#### Scenario: pypandoc 解析器在独立文件
|
||||||
- **WHEN** 使用 pypandoc 解析器
|
- **WHEN** 使用 pypandoc 解析器
|
||||||
- **THEN** 从 readers/doc/pypandoc.py 导入
|
- **THEN** 从 readers/doc/pypandoc.py 导入
|
||||||
|
|
||||||
|
### Requirement: DOC Reader 测试使用静态文件
|
||||||
|
DOC Reader 测试 MUST 使用 `tests/test_readers/fixtures/doc/` 下的静态文件。
|
||||||
|
|
||||||
|
#### Scenario: 测试使用 simple.doc
|
||||||
|
- **WHEN** 测试 DOC Reader 基础解析能力
|
||||||
|
- **THEN** 使用 `simple.doc` 静态文件
|
||||||
|
|
||||||
|
#### Scenario: 测试使用 with_headings.doc
|
||||||
|
- **WHEN** 测试 DOC Reader 标题解析
|
||||||
|
- **THEN** 使用 `with_headings.doc` 静态文件
|
||||||
|
|
||||||
|
#### Scenario: 测试使用 with_table.doc
|
||||||
|
- **WHEN** 测试 DOC Reader 表格解析
|
||||||
|
- **THEN** 使用 `with_table.doc` 静态文件
|
||||||
|
|||||||
@@ -36,3 +36,18 @@ PPT 文档解析能力,支持解析 Microsoft PowerPoint 97-2003 旧格式文
|
|||||||
#### Scenario: markitdown 解析器在独立文件
|
#### Scenario: markitdown 解析器在独立文件
|
||||||
- **WHEN** 使用 markitdown 解析器
|
- **WHEN** 使用 markitdown 解析器
|
||||||
- **THEN** 从 readers/ppt/markitdown.py 导入
|
- **THEN** 从 readers/ppt/markitdown.py 导入
|
||||||
|
|
||||||
|
### Requirement: PPT Reader 测试使用静态文件
|
||||||
|
PPT Reader 测试 MUST 使用 `tests/test_readers/fixtures/ppt/` 下的静态文件。
|
||||||
|
|
||||||
|
#### Scenario: 测试使用 simple.ppt
|
||||||
|
- **WHEN** 测试 PPT Reader 基础解析能力
|
||||||
|
- **THEN** 使用 `simple.ppt` 静态文件
|
||||||
|
|
||||||
|
#### Scenario: 测试使用 multiple_slides.ppt
|
||||||
|
- **WHEN** 测试 PPT Reader 多幻灯片解析
|
||||||
|
- **THEN** 使用 `multiple_slides.ppt` 静态文件
|
||||||
|
|
||||||
|
#### Scenario: 测试使用 with_images.ppt
|
||||||
|
- **WHEN** 测试 PPT Reader 图片处理(可选)
|
||||||
|
- **THEN** 使用 `with_images.ppt` 静态文件
|
||||||
|
|||||||
@@ -117,3 +117,60 @@ Reader MUST 正确处理包含特殊字符的内容。
|
|||||||
#### Scenario: 每个 PDF Reader 有独立测试
|
#### Scenario: 每个 PDF Reader 有独立测试
|
||||||
- **WHEN** 查看 test_readers/test_pdf/ 目录
|
- **WHEN** 查看 test_readers/test_pdf/ 目录
|
||||||
- **THEN** 存在 test_pypdf.py、test_markitdown.py、test_docling.py 等独立文件
|
- **THEN** 存在 test_pypdf.py、test_markitdown.py、test_docling.py 等独立文件
|
||||||
|
|
||||||
|
### Requirement: 旧格式文档测试覆盖
|
||||||
|
doc/xls/ppt 旧格式文档 MUST 有与新格式(docx/xlsx/pptx)一致的测试覆盖。
|
||||||
|
|
||||||
|
#### Scenario: doc 有一致性测试
|
||||||
|
- **WHEN** 查看 `tests/test_readers/test_doc/`
|
||||||
|
- **THEN** 存在 `test_consistency.py` 测试所有 DOC Readers 解析结果一致性
|
||||||
|
|
||||||
|
#### Scenario: xls 有一致性测试
|
||||||
|
- **WHEN** 查看 `tests/test_readers/test_xls/`
|
||||||
|
- **THEN** 存在 `test_consistency.py` 测试所有 XLS Readers 解析结果一致性
|
||||||
|
|
||||||
|
#### Scenario: ppt 有一致性测试
|
||||||
|
- **WHEN** 查看 `tests/test_readers/test_ppt/`
|
||||||
|
- **THEN** 存在 `test_consistency.py` 测试所有 PPT Readers 解析结果一致性
|
||||||
|
|
||||||
|
#### Scenario: doc 各解析器独立测试
|
||||||
|
- **WHEN** 查看 `tests/test_readers/test_doc/`
|
||||||
|
- **THEN** 每个解析器有独立测试文件(如 `test_markitdown_doc.py`、`test_pypandoc_doc.py`)
|
||||||
|
|
||||||
|
#### Scenario: xls 各解析器独立测试
|
||||||
|
- **WHEN** 查看 `tests/test_readers/test_xls/`
|
||||||
|
- **THEN** 每个解析器有独立测试文件(如 `test_markitdown_xls.py`、`test_unstructured_xls.py`、`test_pandas_xls.py`)
|
||||||
|
|
||||||
|
#### Scenario: ppt 各解析器独立测试
|
||||||
|
- **WHEN** 查看 `tests/test_readers/test_ppt/`
|
||||||
|
- **THEN** 每个解析器有独立测试文件(如 `test_markitdown_ppt.py`)
|
||||||
|
|
||||||
|
### Requirement: 旧格式测试使用静态文件
|
||||||
|
旧格式文档测试 MUST 使用静态测试文件,而非尝试自动化创建。
|
||||||
|
|
||||||
|
#### Scenario: doc 测试使用静态文件
|
||||||
|
- **WHEN** 运行 doc 相关测试
|
||||||
|
- **THEN** 测试从 `tests/test_readers/fixtures/doc/` 读取静态文件
|
||||||
|
|
||||||
|
#### Scenario: xls 测试使用静态文件
|
||||||
|
- **WHEN** 运行 xls 相关测试
|
||||||
|
- **THEN** 测试从 `tests/test_readers/fixtures/xls/` 读取静态文件
|
||||||
|
|
||||||
|
#### Scenario: ppt 测试使用静态文件
|
||||||
|
- **WHEN** 运行 ppt 相关测试
|
||||||
|
- **THEN** 测试从 `tests/test_readers/fixtures/ppt/` 读取静态文件
|
||||||
|
|
||||||
|
### Requirement: 静态文件缺失时优雅跳过
|
||||||
|
当静态测试文件不存在时,测试 MUST 优雅跳过,而非失败。
|
||||||
|
|
||||||
|
#### Scenario: doc 静态文件不存在时跳过
|
||||||
|
- **WHEN** `simple.doc` 不存在
|
||||||
|
- **THEN** 相关测试使用 `pytest.skip()` 跳过
|
||||||
|
|
||||||
|
#### Scenario: xls 静态文件不存在时跳过
|
||||||
|
- **WHEN** `simple.xls` 不存在
|
||||||
|
- **THEN** 相关测试使用 `pytest.skip()` 跳过
|
||||||
|
|
||||||
|
#### Scenario: ppt 静态文件不存在时跳过
|
||||||
|
- **WHEN** `simple.ppt` 不存在
|
||||||
|
- **THEN** 相关测试使用 `pytest.skip()` 跳过
|
||||||
|
|||||||
@@ -59,6 +59,18 @@ tests/test_readers/conftest.py MUST 提供 Reader 测试专用的 fixtures。
|
|||||||
- **WHEN** 测试需要临时 XLSX 文件
|
- **WHEN** 测试需要临时 XLSX 文件
|
||||||
- **THEN** 可以使用 `temp_xlsx` fixture 创建临时 XLSX 文件
|
- **THEN** 可以使用 `temp_xlsx` fixture 创建临时 XLSX 文件
|
||||||
|
|
||||||
|
#### Scenario: 提供 doc 静态文件 fixtures
|
||||||
|
- **WHEN** 测试需要 doc 静态测试文件
|
||||||
|
- **THEN** 可以使用 `simple_doc_path`、`with_headings_doc_path`、`with_table_doc_path`
|
||||||
|
|
||||||
|
#### Scenario: 提供 xls 静态文件 fixtures
|
||||||
|
- **WHEN** 测试需要 xls 静态测试文件
|
||||||
|
- **THEN** 可以使用 `simple_xls_path`、`multiple_sheets_xls_path`、`with_formulas_xls_path`
|
||||||
|
|
||||||
|
#### Scenario: 提供 ppt 静态文件 fixtures
|
||||||
|
- **WHEN** 测试需要 ppt 静态测试文件
|
||||||
|
- **THEN** 可以使用 `simple_ppt_path`、`multiple_slides_ppt_path`、`with_images_ppt_path`
|
||||||
|
|
||||||
### Requirement: CLI 专用 fixtures
|
### Requirement: CLI 专用 fixtures
|
||||||
tests/test_cli/conftest.py MUST 提供 CLI 测试专用的 fixtures。
|
tests/test_cli/conftest.py MUST 提供 CLI 测试专用的 fixtures。
|
||||||
|
|
||||||
@@ -106,3 +118,54 @@ temp_html fixture MUST 支持创建包含各种元素的 HTML 文件。
|
|||||||
#### Scenario: 创建包含标题和段落的 HTML
|
#### Scenario: 创建包含标题和段落的 HTML
|
||||||
- **WHEN** 调用 `temp_html(content="<h1>标题</h1><p>段落</p>")`
|
- **WHEN** 调用 `temp_html(content="<h1>标题</h1><p>段落</p>")`
|
||||||
- **THEN** 创建包含指定内容的 HTML 文件
|
- **THEN** 创建包含指定内容的 HTML 文件
|
||||||
|
|
||||||
|
### Requirement: 静态测试文件目录结构
|
||||||
|
项目 MUST 在 `tests/test_readers/fixtures/` 下按格式类型组织静态测试文件。
|
||||||
|
|
||||||
|
#### Scenario: doc 静态文件目录
|
||||||
|
- **WHEN** 查看 `tests/test_readers/fixtures/doc/`
|
||||||
|
- **THEN** 目录存在且包含 .doc 静态测试文件
|
||||||
|
|
||||||
|
#### Scenario: xls 静态文件目录
|
||||||
|
- **WHEN** 查看 `tests/test_readers/fixtures/xls/`
|
||||||
|
- **THEN** 目录存在且包含 .xls 静态测试文件
|
||||||
|
|
||||||
|
#### Scenario: ppt 静态文件目录
|
||||||
|
- **WHEN** 查看 `tests/test_readers/fixtures/ppt/`
|
||||||
|
- **THEN** 目录存在且包含 .ppt 静态测试文件
|
||||||
|
|
||||||
|
### Requirement: fixtures 目录所有文件纳入 Git LFS
|
||||||
|
`tests/test_readers/fixtures/` 目录下的 ALL 文件 MUST 纳入 Git LFS 管理。
|
||||||
|
|
||||||
|
#### Scenario: .gitattributes 配置正确
|
||||||
|
- **WHEN** 查看 `.gitattributes`
|
||||||
|
- **THEN** 包含 `tests/test_readers/fixtures/**/*` 的 LFS 配置,匹配该目录下所有文件
|
||||||
|
|
||||||
|
### Requirement: fixtures 目录仅存放静态文件
|
||||||
|
`tests/test_readers/fixtures/` 目录 MUST 仅用于存放预先准备的静态测试文件,禁止在测试中向该目录动态生成临时文件。
|
||||||
|
|
||||||
|
#### Scenario: 不向 fixtures 目录写入临时文件
|
||||||
|
- **WHEN** 测试运行时
|
||||||
|
- **THEN** 不会在 `tests/test_readers/fixtures/` 下创建或修改文件
|
||||||
|
- **AND** 临时文件使用 pytest 的 tmp_path 在其他位置创建
|
||||||
|
|
||||||
|
### Requirement: 静态测试文件 Fixture
|
||||||
|
`tests/test_readers/conftest.py` MUST 提供访问静态测试文件的 fixtures。
|
||||||
|
|
||||||
|
#### Scenario: 提供目录路径 fixture
|
||||||
|
- **WHEN** 测试需要访问静态文件目录
|
||||||
|
- **THEN** 可以使用 `doc_fixture_path`、`xls_fixture_path`、`ppt_fixture_path` 获取对应目录路径
|
||||||
|
|
||||||
|
#### Scenario: 提供单个文件 fixture
|
||||||
|
- **WHEN** 测试需要访问特定静态文件
|
||||||
|
- **THEN** 可以使用 `simple_doc_path`、`with_headings_doc_path` 等便捷 fixture
|
||||||
|
- **AND** 文件不存在时自动 pytest.skip
|
||||||
|
|
||||||
|
### Requirement: fixtures 使用规范写入开发文档
|
||||||
|
fixtures 目录的使用规范 MUST 写入 README.md 开发文档。
|
||||||
|
|
||||||
|
#### Scenario: README 包含 fixtures 规范
|
||||||
|
- **WHEN** 查看 README.md
|
||||||
|
- **THEN** 包含 fixtures 目录的用途说明
|
||||||
|
- **AND** 包含静态文件与临时文件的区别说明
|
||||||
|
- **AND** 包含 Git LFS 配置说明
|
||||||
|
|||||||
@@ -66,3 +66,18 @@ XLS 文档解析能力,支持解析 Microsoft Excel 97-2003 旧格式文档。
|
|||||||
#### Scenario: pandas 解析器在独立文件
|
#### Scenario: pandas 解析器在独立文件
|
||||||
- **WHEN** 使用 pandas 解析器
|
- **WHEN** 使用 pandas 解析器
|
||||||
- **THEN** 从 readers/xls/pandas.py 导入
|
- **THEN** 从 readers/xls/pandas.py 导入
|
||||||
|
|
||||||
|
### Requirement: XLS Reader 测试使用静态文件
|
||||||
|
XLS Reader 测试 MUST 使用 `tests/test_readers/fixtures/xls/` 下的静态文件。
|
||||||
|
|
||||||
|
#### Scenario: 测试使用 simple.xls
|
||||||
|
- **WHEN** 测试 XLS Reader 基础解析能力
|
||||||
|
- **THEN** 使用 `simple.xls` 静态文件
|
||||||
|
|
||||||
|
#### Scenario: 测试使用 multiple_sheets.xls
|
||||||
|
- **WHEN** 测试 XLS Reader 多工作表解析
|
||||||
|
- **THEN** 使用 `multiple_sheets.xls` 静态文件
|
||||||
|
|
||||||
|
#### Scenario: 测试使用 with_formulas.xls
|
||||||
|
- **WHEN** 测试 XLS Reader 公式结果读取
|
||||||
|
- **THEN** 使用 `with_formulas.xls` 静态文件
|
||||||
|
|||||||
@@ -195,3 +195,87 @@ def temp_xlsx(tmp_path):
|
|||||||
|
|
||||||
return _create_xlsx
|
return _create_xlsx
|
||||||
|
|
||||||
|
|
||||||
|
# 静态测试文件目录
|
||||||
|
FIXTURES_DIR = Path(__file__).parent / "fixtures"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def doc_fixture_path():
|
||||||
|
"""返回 DOC 静态测试文件目录"""
|
||||||
|
return FIXTURES_DIR / "doc"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def xls_fixture_path():
|
||||||
|
"""返回 XLS 静态测试文件目录"""
|
||||||
|
return FIXTURES_DIR / "xls"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def ppt_fixture_path():
|
||||||
|
"""返回 PPT 静态测试文件目录"""
|
||||||
|
return FIXTURES_DIR / "ppt"
|
||||||
|
|
||||||
|
|
||||||
|
def _get_static_file_path(fixture_dir, filename):
|
||||||
|
"""获取静态文件路径,不存在时跳过测试"""
|
||||||
|
file_path = fixture_dir / filename
|
||||||
|
if not file_path.exists():
|
||||||
|
pytest.skip(f"静态测试文件不存在: {file_path}")
|
||||||
|
return str(file_path)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def simple_doc_path(doc_fixture_path):
|
||||||
|
"""返回简单 DOC 测试文件路径"""
|
||||||
|
return _get_static_file_path(doc_fixture_path, "simple.doc")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def with_headings_doc_path(doc_fixture_path):
|
||||||
|
"""返回带标题的 DOC 测试文件路径"""
|
||||||
|
return _get_static_file_path(doc_fixture_path, "with_headings.doc")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def with_table_doc_path(doc_fixture_path):
|
||||||
|
"""返回带表格的 DOC 测试文件路径"""
|
||||||
|
return _get_static_file_path(doc_fixture_path, "with_table.doc")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def simple_xls_path(xls_fixture_path):
|
||||||
|
"""返回简单 XLS 测试文件路径"""
|
||||||
|
return _get_static_file_path(xls_fixture_path, "simple.xls")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def multiple_sheets_xls_path(xls_fixture_path):
|
||||||
|
"""返回多工作表 XLS 测试文件路径"""
|
||||||
|
return _get_static_file_path(xls_fixture_path, "multiple_sheets.xls")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def with_formulas_xls_path(xls_fixture_path):
|
||||||
|
"""返回带公式 XLS 测试文件路径"""
|
||||||
|
return _get_static_file_path(xls_fixture_path, "with_formulas.xls")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def simple_ppt_path(ppt_fixture_path):
|
||||||
|
"""返回简单 PPT 测试文件路径"""
|
||||||
|
return _get_static_file_path(ppt_fixture_path, "simple.ppt")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def multiple_slides_ppt_path(ppt_fixture_path):
|
||||||
|
"""返回多幻灯片 PPT 测试文件路径"""
|
||||||
|
return _get_static_file_path(ppt_fixture_path, "multiple_slides.ppt")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def with_images_ppt_path(ppt_fixture_path):
|
||||||
|
"""返回带图片 PPT 测试文件路径"""
|
||||||
|
return _get_static_file_path(ppt_fixture_path, "with_images.ppt")
|
||||||
|
|
||||||
|
|||||||
BIN
tests/test_readers/fixtures/doc/simple.doc
LFS
Normal file
BIN
tests/test_readers/fixtures/doc/simple.doc
LFS
Normal file
Binary file not shown.
BIN
tests/test_readers/fixtures/doc/with_headings.doc
LFS
Normal file
BIN
tests/test_readers/fixtures/doc/with_headings.doc
LFS
Normal file
Binary file not shown.
BIN
tests/test_readers/fixtures/doc/with_table.doc
LFS
Normal file
BIN
tests/test_readers/fixtures/doc/with_table.doc
LFS
Normal file
Binary file not shown.
BIN
tests/test_readers/fixtures/ppt/multiple_slides.ppt
LFS
Normal file
BIN
tests/test_readers/fixtures/ppt/multiple_slides.ppt
LFS
Normal file
Binary file not shown.
BIN
tests/test_readers/fixtures/ppt/simple.ppt
LFS
Normal file
BIN
tests/test_readers/fixtures/ppt/simple.ppt
LFS
Normal file
Binary file not shown.
BIN
tests/test_readers/fixtures/ppt/with_images.ppt
LFS
Normal file
BIN
tests/test_readers/fixtures/ppt/with_images.ppt
LFS
Normal file
Binary file not shown.
BIN
tests/test_readers/fixtures/xls/multiple_sheets.xls
LFS
Normal file
BIN
tests/test_readers/fixtures/xls/multiple_sheets.xls
LFS
Normal file
Binary file not shown.
BIN
tests/test_readers/fixtures/xls/simple.xls
LFS
Normal file
BIN
tests/test_readers/fixtures/xls/simple.xls
LFS
Normal file
Binary file not shown.
BIN
tests/test_readers/fixtures/xls/with_formulas.xls
LFS
Normal file
BIN
tests/test_readers/fixtures/xls/with_formulas.xls
LFS
Normal file
Binary file not shown.
@@ -5,7 +5,7 @@ from readers.doc import markitdown, pypandoc
|
|||||||
|
|
||||||
|
|
||||||
class TestDocReadersConsistency:
|
class TestDocReadersConsistency:
|
||||||
"""验证 DOC Readers 模块结构正确。"""
|
"""验证所有 DOC Readers 解析同一文件时核心文字内容一致。"""
|
||||||
|
|
||||||
def test_parsers_importable(self):
|
def test_parsers_importable(self):
|
||||||
"""测试所有 parser 模块可以正确导入。"""
|
"""测试所有 parser 模块可以正确导入。"""
|
||||||
@@ -19,3 +19,26 @@ class TestDocReadersConsistency:
|
|||||||
"""测试 parse 函数是可调用的。"""
|
"""测试 parse 函数是可调用的。"""
|
||||||
assert callable(markitdown.parse)
|
assert callable(markitdown.parse)
|
||||||
assert callable(pypandoc.parse)
|
assert callable(pypandoc.parse)
|
||||||
|
|
||||||
|
def test_all_readers_parse_same_content(self, simple_doc_path):
|
||||||
|
"""测试所有 Readers 解析同一文件时核心内容一致。"""
|
||||||
|
# 收集所有 readers 的解析结果
|
||||||
|
parsers = [
|
||||||
|
("markitdown", markitdown.parse),
|
||||||
|
("pypandoc", pypandoc.parse),
|
||||||
|
]
|
||||||
|
|
||||||
|
successful_results = []
|
||||||
|
for name, parser in parsers:
|
||||||
|
content, error = parser(simple_doc_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} 解析结果不包含核心内容"
|
||||||
|
|||||||
@@ -23,3 +23,27 @@ class TestMarkitdownDocReaderParse:
|
|||||||
# 验证返回 None 和错误信息
|
# 验证返回 None 和错误信息
|
||||||
assert content is None
|
assert content is None
|
||||||
assert error is not None
|
assert error is not None
|
||||||
|
|
||||||
|
def test_parse_simple_doc(self, simple_doc_path):
|
||||||
|
"""测试解析简单 DOC 文件。"""
|
||||||
|
content, error = markitdown.parse(simple_doc_path)
|
||||||
|
|
||||||
|
# 只要不崩溃即可,不强制要求成功解析
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|
||||||
|
def test_parse_with_headings_doc(self, with_headings_doc_path):
|
||||||
|
"""测试解析带标题的 DOC 文件。"""
|
||||||
|
content, error = markitdown.parse(with_headings_doc_path)
|
||||||
|
|
||||||
|
# 只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|
||||||
|
def test_parse_with_table_doc(self, with_table_doc_path):
|
||||||
|
"""测试解析带表格的 DOC 文件。"""
|
||||||
|
content, error = markitdown.parse(with_table_doc_path)
|
||||||
|
|
||||||
|
# 只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|||||||
@@ -23,3 +23,11 @@ class TestPypandocDocReaderParse:
|
|||||||
# 验证返回 None 和错误信息
|
# 验证返回 None 和错误信息
|
||||||
assert content is None
|
assert content is None
|
||||||
assert error is not None
|
assert error is not None
|
||||||
|
|
||||||
|
def test_parse_simple_doc(self, simple_doc_path):
|
||||||
|
"""测试解析简单 DOC 文件。"""
|
||||||
|
content, error = pypandoc.parse(simple_doc_path)
|
||||||
|
|
||||||
|
# pypandoc 可能需要额外依赖,只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from readers.ppt import markitdown
|
|||||||
|
|
||||||
|
|
||||||
class TestPptReadersConsistency:
|
class TestPptReadersConsistency:
|
||||||
"""验证 PPT Readers 模块结构正确。"""
|
"""验证所有 PPT Readers 解析同一文件时核心文字内容一致。"""
|
||||||
|
|
||||||
def test_parsers_importable(self):
|
def test_parsers_importable(self):
|
||||||
"""测试所有 parser 模块可以正确导入。"""
|
"""测试所有 parser 模块可以正确导入。"""
|
||||||
@@ -16,3 +16,25 @@ class TestPptReadersConsistency:
|
|||||||
def test_parser_functions_callable(self):
|
def test_parser_functions_callable(self):
|
||||||
"""测试 parse 函数是可调用的。"""
|
"""测试 parse 函数是可调用的。"""
|
||||||
assert callable(markitdown.parse)
|
assert callable(markitdown.parse)
|
||||||
|
|
||||||
|
def test_all_readers_parse_same_content(self, simple_ppt_path):
|
||||||
|
"""测试所有 Readers 解析同一文件时核心内容一致。"""
|
||||||
|
# 收集所有 readers 的解析结果
|
||||||
|
parsers = [
|
||||||
|
("markitdown", markitdown.parse),
|
||||||
|
]
|
||||||
|
|
||||||
|
successful_results = []
|
||||||
|
for name, parser in parsers:
|
||||||
|
content, error = parser(simple_ppt_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} 解析结果不包含核心内容"
|
||||||
|
|||||||
@@ -23,3 +23,19 @@ class TestMarkitdownPptReaderParse:
|
|||||||
# 验证返回 None 和错误信息
|
# 验证返回 None 和错误信息
|
||||||
assert content is None
|
assert content is None
|
||||||
assert error is not None
|
assert error is not None
|
||||||
|
|
||||||
|
def test_parse_simple_ppt(self, simple_ppt_path):
|
||||||
|
"""测试解析简单 PPT 文件。"""
|
||||||
|
content, error = markitdown.parse(simple_ppt_path)
|
||||||
|
|
||||||
|
# 只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|
||||||
|
def test_parse_multiple_slides_ppt(self, multiple_slides_ppt_path):
|
||||||
|
"""测试解析多幻灯片 PPT 文件。"""
|
||||||
|
content, error = markitdown.parse(multiple_slides_ppt_path)
|
||||||
|
|
||||||
|
# 只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from readers.xls import unstructured, markitdown, pandas
|
|||||||
|
|
||||||
|
|
||||||
class TestXlsReadersConsistency:
|
class TestXlsReadersConsistency:
|
||||||
"""验证 XLS Readers 模块结构正确。"""
|
"""验证所有 XLS Readers 解析同一文件时核心文字内容一致。"""
|
||||||
|
|
||||||
def test_parsers_importable(self):
|
def test_parsers_importable(self):
|
||||||
"""测试所有 parser 模块可以正确导入。"""
|
"""测试所有 parser 模块可以正确导入。"""
|
||||||
@@ -22,3 +22,27 @@ class TestXlsReadersConsistency:
|
|||||||
assert callable(unstructured.parse)
|
assert callable(unstructured.parse)
|
||||||
assert callable(markitdown.parse)
|
assert callable(markitdown.parse)
|
||||||
assert callable(pandas.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} 解析结果不包含核心内容"
|
||||||
|
|||||||
@@ -23,3 +23,27 @@ class TestMarkitdownXlsReaderParse:
|
|||||||
# 验证返回 None 和错误信息
|
# 验证返回 None 和错误信息
|
||||||
assert content is None
|
assert content is None
|
||||||
assert error is not None
|
assert error is not None
|
||||||
|
|
||||||
|
def test_parse_simple_xls(self, simple_xls_path):
|
||||||
|
"""测试解析简单 XLS 文件。"""
|
||||||
|
content, error = markitdown.parse(simple_xls_path)
|
||||||
|
|
||||||
|
# 只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|
||||||
|
def test_parse_multiple_sheets_xls(self, multiple_sheets_xls_path):
|
||||||
|
"""测试解析多工作表 XLS 文件。"""
|
||||||
|
content, error = markitdown.parse(multiple_sheets_xls_path)
|
||||||
|
|
||||||
|
# 只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|
||||||
|
def test_parse_with_formulas_xls(self, with_formulas_xls_path):
|
||||||
|
"""测试解析带公式 XLS 文件。"""
|
||||||
|
content, error = markitdown.parse(with_formulas_xls_path)
|
||||||
|
|
||||||
|
# 只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|||||||
@@ -23,3 +23,11 @@ class TestPandasXlsReaderParse:
|
|||||||
# 验证返回 None 和错误信息
|
# 验证返回 None 和错误信息
|
||||||
assert content is None
|
assert content is None
|
||||||
assert error is not None
|
assert error is not None
|
||||||
|
|
||||||
|
def test_parse_simple_xls(self, simple_xls_path):
|
||||||
|
"""测试解析简单 XLS 文件。"""
|
||||||
|
content, error = pandas.parse(simple_xls_path)
|
||||||
|
|
||||||
|
# 只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|||||||
@@ -23,3 +23,11 @@ class TestUnstructuredXlsReaderParse:
|
|||||||
# 验证返回 None 和错误信息
|
# 验证返回 None 和错误信息
|
||||||
assert content is None
|
assert content is None
|
||||||
assert error is not None
|
assert error is not None
|
||||||
|
|
||||||
|
def test_parse_simple_xls(self, simple_xls_path):
|
||||||
|
"""测试解析简单 XLS 文件。"""
|
||||||
|
content, error = unstructured.parse(simple_xls_path)
|
||||||
|
|
||||||
|
# unstructured 可能需要额外依赖,只要不崩溃即可
|
||||||
|
if content is not None:
|
||||||
|
assert len(content.strip()) > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user