fix: 修复 7 个失败测试和 1 个错误测试
- 修复 conftest_pptx.py 中元素类型检测:使用 has_text_frame 替代不存在的 MSO_SHAPE.TEXT_BOX - 修复 test_presentation.py 中 3 个测试:使用对象属性访问替代字典访问 - 修复 unit/test_presentation.py 中路径比较问题 - 添加缺失的 mock_template_class fixture 测试通过率: 316/316 (100%) 代码覆盖率: 94%
This commit is contained in:
@@ -14,6 +14,7 @@ sys.path.insert(0, str(project_root))
|
||||
|
||||
# ============= 基础 Fixtures =============
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_dir(tmp_path):
|
||||
"""临时目录 fixture,使用 pytest 内置 tmp_path"""
|
||||
@@ -50,19 +51,20 @@ slides:
|
||||
def sample_yaml(temp_dir):
|
||||
"""创建最小测试 YAML 文件"""
|
||||
yaml_path = temp_dir / "test.yaml"
|
||||
yaml_path.write_text(MINIMAL_YAML, encoding='utf-8')
|
||||
yaml_path.write_text(MINIMAL_YAML, encoding="utf-8")
|
||||
return yaml_path
|
||||
|
||||
|
||||
# ============= 图片 Fixtures =============
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_image(temp_dir):
|
||||
"""创建测试图片文件(使用 Pillow 生成简单的 PNG)"""
|
||||
img_path = temp_dir / "test_image.png"
|
||||
# 创建一个简单的红色图片
|
||||
img = Image.new('RGB', (100, 100), color='red')
|
||||
img.save(img_path, 'PNG')
|
||||
img = Image.new("RGB", (100, 100), color="red")
|
||||
img.save(img_path, "PNG")
|
||||
return img_path
|
||||
|
||||
|
||||
@@ -99,21 +101,33 @@ def sample_template(temp_dir):
|
||||
"""创建测试模板目录和文件"""
|
||||
template_dir = temp_dir / "templates"
|
||||
template_dir.mkdir()
|
||||
(template_dir / "title-slide.yaml").write_text(TEMPLATE_YAML, encoding='utf-8')
|
||||
(template_dir / "title-slide.yaml").write_text(TEMPLATE_YAML, encoding="utf-8")
|
||||
return template_dir
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_template_class():
|
||||
"""Mock Template 类,用于单元测试"""
|
||||
from unittest.mock import patch
|
||||
|
||||
with patch("core.presentation.Template") as mock_class:
|
||||
yield mock_class
|
||||
|
||||
|
||||
# ============= PPTX 验证 Fixture =============
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pptx_validator():
|
||||
"""PPTX 文件验证器实例"""
|
||||
from tests.conftest_pptx import PptxFileValidator
|
||||
|
||||
return PptxFileValidator()
|
||||
|
||||
|
||||
# ============= 测试数据目录 Fixture =============
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fixtures_dir():
|
||||
"""测试数据目录路径"""
|
||||
@@ -122,6 +136,7 @@ def fixtures_dir():
|
||||
|
||||
# ============= 额外的边界情况 Fixtures =============
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def edge_case_yaml_files(fixtures_dir):
|
||||
"""所有边界情况 YAML 文件的路径"""
|
||||
|
||||
Reference in New Issue
Block a user