1
0

fix: 修复测试问题,提升测试通过率

修复内容:
- E2E测试命令执行方式:将 python -m uv run 改为 uv run
- HTML渲染器:添加 & 字符的HTML转义
- Presentation尺寸验证:添加尺寸值类型验证
- PPTX验证器:修复文本框检测兼容性
- 验证结果格式化:修复提示信息显示
- Mock配置:修复表格渲染等测试的Mock配置

测试结果:
- 修复前: 264 通过, 42 失败, 1 错误
- 修复后: 297 通过, 9 失败, 1 错误

剩余9个失败为待实现的功能增强(验证器模板变量验证)
This commit is contained in:
2026-03-03 00:42:39 +08:00
parent f273cef195
commit c73bd0fedd
12 changed files with 318 additions and 401 deletions

View File

@@ -15,13 +15,10 @@ class TestCheckCmd:
def run_check(self, *args):
"""辅助函数:运行 check 命令"""
cmd = [sys.executable, "-m", "uv", "run", "python", "yaml2pptx.py", "check"]
cmd = ["uv", "run", "python", "yaml2pptx.py", "check"]
cmd.extend(args)
result = subprocess.run(
cmd,
capture_output=True,
text=True,
cwd=Path(__file__).parent.parent.parent
cmd, capture_output=True, text=True, cwd=Path(__file__).parent.parent.parent
)
return result

View File

@@ -16,13 +16,10 @@ class TestConvertCmd:
def run_convert(self, *args):
"""辅助函数:运行 convert 命令"""
cmd = [sys.executable, "-m", "uv", "run", "python", "yaml2pptx.py", "convert"]
cmd = ["uv", "run", "python", "yaml2pptx.py", "convert"]
cmd.extend(args)
result = subprocess.run(
cmd,
capture_output=True,
text=True,
cwd=Path(__file__).parent.parent.parent
cmd, capture_output=True, text=True, cwd=Path(__file__).parent.parent.parent
)
return result
@@ -37,19 +34,29 @@ class TestConvertCmd:
def test_auto_output_filename(self, sample_yaml, temp_dir):
"""测试自动生成输出文件名"""
# 在 temp_dir 中运行
# sample_yaml 位于 temp_dir 中,转换时输出也会在 temp_dir
# 但因为 cwd 是项目根目录,所以输出文件的路径需要计算
# 实际上,由于 sample_yaml 使用 tempfile输出会在 temp_dir 中
result = subprocess.run(
[sys.executable, "-m", "uv", "run", "python",
"yaml2pptx.py", "convert", str(sample_yaml)],
[
"uv",
"run",
"python",
"yaml2pptx.py",
"convert",
str(sample_yaml),
],
capture_output=True,
text=True,
cwd=temp_dir
cwd=Path(__file__).parent.parent.parent,
)
assert result.returncode == 0
# 应该生成与输入同名的 .pptx 文件
assert result.returncode == 0, f"Command failed: {result.stderr}"
# 应该生成与输入同名的 .pptx 文件(在 temp_dir 中)
expected_output = temp_dir / "test.pptx"
assert expected_output.exists()
assert expected_output.exists(), (
f"Expected {expected_output} to exist, but didn't"
)
def test_conversion_with_template(self, temp_dir, sample_template):
"""测试使用模板转换"""
@@ -67,9 +74,7 @@ slides:
output = temp_dir / "output.pptx"
result = self.run_convert(
str(yaml_path),
str(output),
"--template-dir", str(sample_template)
str(yaml_path), str(output), "--template-dir", str(sample_template)
)
assert result.returncode == 0
@@ -78,11 +83,7 @@ slides:
def test_skip_validation(self, sample_yaml, temp_dir):
"""测试跳过验证"""
output = temp_dir / "output.pptx"
result = self.run_convert(
str(sample_yaml),
str(output),
"--skip-validation"
)
result = self.run_convert(str(sample_yaml), str(output), "--skip-validation")
assert result.returncode == 0
assert output.exists()
@@ -95,11 +96,7 @@ slides:
output.write_text("existing")
# 使用 --force 应该覆盖
result = self.run_convert(
str(sample_yaml),
str(output),
"--force"
)
result = self.run_convert(str(sample_yaml), str(output), "--force")
assert result.returncode == 0
# 文件应该是有效的 PPTX不是原来的文本
@@ -129,7 +126,12 @@ slides:
def test_conversion_with_all_element_types(self, temp_dir, sample_image):
"""测试转换包含所有元素类型的 YAML"""
fixtures_yaml = Path(__file__).parent.parent / "fixtures" / "yaml_samples" / "full_features.yaml"
fixtures_yaml = (
Path(__file__).parent.parent
/ "fixtures"
/ "yaml_samples"
/ "full_features.yaml"
)
if not fixtures_yaml.exists():
pytest.skip("full_features.yaml not found")
@@ -158,7 +160,7 @@ slides:
size: 24
"""
yaml_path = temp_dir / "test.yaml"
yaml_path.write_text(yaml_content, encoding='utf-8')
yaml_path.write_text(yaml_content, encoding="utf-8")
output = temp_dir / "output.pptx"
result = self.run_convert(str(yaml_path), str(output))
@@ -174,9 +176,9 @@ slides:
def test_different_slide_sizes(self, temp_dir):
"""测试不同的幻灯片尺寸"""
for size in ["16:9", "4:3"]:
yaml_content = f"""
yaml_content = f'''
metadata:
size: {size}
size: "{size}"
slides:
- elements:
@@ -185,7 +187,7 @@ slides:
content: "Size {size}"
font:
size: 24
"""
'''
yaml_path = temp_dir / f"test_{size.replace(':', '')}.yaml"
yaml_path.write_text(yaml_content)