"""Reader 测试专用 fixtures。""" import pytest from pathlib import Path @pytest.fixture def temp_html(tmp_path): """创建临时 HTML 文件的 fixture 工厂。 Args: content: HTML 内容字符串 encoding: 文件编码,默认 'utf-8' Returns: str: 临时文件路径 """ def _create_html(content="
Test
", encoding='utf-8'): file_path = tmp_path / "test.html" # 如果内容不包含完整的 HTML 结构,添加基本结构 if not content.strip().startswith('{content}" with open(file_path, 'w', encoding=encoding) as f: f.write(content) return str(file_path) return _create_html # 静态测试文件目录 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")