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:
@@ -30,12 +30,12 @@ class HtmlRenderer:
|
||||
elements_html = ""
|
||||
|
||||
bg_style = ""
|
||||
if slide_data.get('background'):
|
||||
bg = slide_data['background']
|
||||
if 'color' in bg:
|
||||
if slide_data.get("background"):
|
||||
bg = slide_data["background"]
|
||||
if "color" in bg:
|
||||
bg_style = f"background: {bg['color']};"
|
||||
|
||||
for elem in slide_data.get('elements', []):
|
||||
for elem in slide_data.get("elements", []):
|
||||
try:
|
||||
if isinstance(elem, TextElement):
|
||||
elements_html += self.render_text(elem)
|
||||
@@ -46,7 +46,9 @@ class HtmlRenderer:
|
||||
elif isinstance(elem, ImageElement):
|
||||
elements_html += self.render_image(elem, base_path)
|
||||
except Exception as e:
|
||||
elements_html += f'<div class="element" style="color: red;">渲染错误: {str(e)}</div>'
|
||||
elements_html += (
|
||||
f'<div class="element" style="color: red;">渲染错误: {str(e)}</div>'
|
||||
)
|
||||
|
||||
return f'''
|
||||
<div class="slide" style="{bg_style}">
|
||||
@@ -70,18 +72,20 @@ class HtmlRenderer:
|
||||
top: {elem.box[1] * DPI}px;
|
||||
width: {elem.box[2] * DPI}px;
|
||||
height: {elem.box[3] * DPI}px;
|
||||
font-size: {elem.font.get('size', 16)}pt;
|
||||
color: {elem.font.get('color', '#000000')};
|
||||
text-align: {elem.font.get('align', 'left')};
|
||||
{'font-weight: bold;' if elem.font.get('bold') else ''}
|
||||
{'font-style: italic;' if elem.font.get('italic') else ''}
|
||||
font-size: {elem.font.get("size", 16)}pt;
|
||||
color: {elem.font.get("color", "#000000")};
|
||||
text-align: {elem.font.get("align", "left")};
|
||||
{"font-weight: bold;" if elem.font.get("bold") else ""}
|
||||
{"font-style: italic;" if elem.font.get("italic") else ""}
|
||||
display: flex;
|
||||
align-items: center;
|
||||
white-space: normal;
|
||||
overflow-wrap: break-word;
|
||||
"""
|
||||
|
||||
content = elem.content.replace('<', '<').replace('>', '>')
|
||||
content = (
|
||||
elem.content.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||
)
|
||||
return f'<div class="element text-element" style="{style}">{content}</div>'
|
||||
|
||||
def render_shape(self, elem: ShapeElement):
|
||||
@@ -95,23 +99,23 @@ class HtmlRenderer:
|
||||
str: HTML 代码
|
||||
"""
|
||||
border_radius = {
|
||||
'rectangle': '0',
|
||||
'ellipse': '50%',
|
||||
'rounded_rectangle': '8px'
|
||||
}.get(elem.shape, '0')
|
||||
"rectangle": "0",
|
||||
"ellipse": "50%",
|
||||
"rounded_rectangle": "8px",
|
||||
}.get(elem.shape, "0")
|
||||
|
||||
style = f"""
|
||||
left: {elem.box[0] * DPI}px;
|
||||
top: {elem.box[1] * DPI}px;
|
||||
width: {elem.box[2] * DPI}px;
|
||||
height: {elem.box[3] * DPI}px;
|
||||
background: {elem.fill if elem.fill else 'transparent'};
|
||||
background: {elem.fill if elem.fill else "transparent"};
|
||||
border-radius: {border_radius};
|
||||
"""
|
||||
|
||||
if elem.line:
|
||||
style += f"""
|
||||
border: {elem.line.get('width', 1)}pt solid {elem.line.get('color', '#000000')};
|
||||
border: {elem.line.get("width", 1)}pt solid {elem.line.get("color", "#000000")};
|
||||
"""
|
||||
|
||||
return f'<div class="element shape-element" style="{style}"></div>'
|
||||
@@ -138,14 +142,14 @@ class HtmlRenderer:
|
||||
cell_style = f"font-size: {elem.style.get('font_size', 14)}pt;"
|
||||
|
||||
if i == 0:
|
||||
if 'header_bg' in elem.style:
|
||||
if "header_bg" in elem.style:
|
||||
cell_style += f"background: {elem.style['header_bg']};"
|
||||
if 'header_color' in elem.style:
|
||||
if "header_color" in elem.style:
|
||||
cell_style += f"color: {elem.style['header_color']};"
|
||||
|
||||
cell_content = str(cell).replace('<', '<').replace('>', '>')
|
||||
cell_content = str(cell).replace("<", "<").replace(">", ">")
|
||||
cells_html += f'<td style="{cell_style}">{cell_content}</td>'
|
||||
rows_html += f'<tr>{cells_html}</tr>'
|
||||
rows_html += f"<tr>{cells_html}</tr>"
|
||||
|
||||
return f'<table class="element table-element" style="{table_style}">{rows_html}</table>'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user