test: add comprehensive pytest test suite
Add complete test infrastructure for yaml2pptx project with 245+ tests covering unit, integration, and end-to-end scenarios. Test structure: - Unit tests: elements, template system, validators, loaders, utils - Integration tests: presentation and rendering flows - E2E tests: CLI commands (convert, check, preview) Key features: - PptxFileValidator for Level 2 PPTX validation (file structure, element count, content matching, position tolerance) - Comprehensive fixtures for test data consistency - Mock-based testing for external dependencies - Test images generated with PIL/Pillow - Boundary case coverage for edge scenarios Dependencies added: - pytest, pytest-cov, pytest-mock - pillow (for test image generation) Documentation updated: - README.md: test running instructions - README_DEV.md: test development guide Co-authored-by: OpenSpec change: add-comprehensive-tests
This commit is contained in:
29
tests/fixtures/yaml_samples/edge_cases/all_element_types_one_slide.yaml
vendored
Normal file
29
tests/fixtures/yaml_samples/edge_cases/all_element_types_one_slide.yaml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
- type: text
|
||||
box: [1, 1, 3, 0.5]
|
||||
content: "All Element Types One Slide"
|
||||
font:
|
||||
size: 18
|
||||
color: "#333333"
|
||||
|
||||
- type: image
|
||||
box: [1, 2, 2, 2]
|
||||
src: "test_image.png"
|
||||
|
||||
- type: shape
|
||||
box: [4, 2, 2, 1]
|
||||
shape: rectangle
|
||||
fill: "#4a90e2"
|
||||
|
||||
- type: table
|
||||
position: [1, 4.5]
|
||||
col_widths: [2, 2, 2]
|
||||
data:
|
||||
- ["H1", "H2", "H3"]
|
||||
- ["D1", "D2", "D3"]
|
||||
style:
|
||||
font_size: 12
|
||||
10
tests/fixtures/yaml_samples/edge_cases/empty_content.yaml
vendored
Normal file
10
tests/fixtures/yaml_samples/edge_cases/empty_content.yaml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
- type: text
|
||||
box: [1, 1, 8, 1]
|
||||
content: ""
|
||||
font:
|
||||
size: 18
|
||||
15
tests/fixtures/yaml_samples/edge_cases/empty_font_attributes.yaml
vendored
Normal file
15
tests/fixtures/yaml_samples/edge_cases/empty_font_attributes.yaml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
# 空字体属性
|
||||
- type: text
|
||||
box: [1, 1, 3, 0.5]
|
||||
content: "Empty Font Attributes"
|
||||
font: {}
|
||||
|
||||
# 空字体
|
||||
- type: text
|
||||
box: [1, 2, 3, 0.5]
|
||||
content: "No Font Field"
|
||||
20
tests/fixtures/yaml_samples/edge_cases/mixed_color_formats.yaml
vendored
Normal file
20
tests/fixtures/yaml_samples/edge_cases/mixed_color_formats.yaml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
# 混合颜色格式
|
||||
- type: text
|
||||
box: [1, 1, 3, 0.5]
|
||||
content: "Mixed Color Formats"
|
||||
font:
|
||||
size: 18
|
||||
color: "#fff"
|
||||
|
||||
- type: shape
|
||||
box: [1, 2, 2, 1]
|
||||
shape: rectangle
|
||||
fill: "#000000"
|
||||
line:
|
||||
color: "#abc"
|
||||
width: 2
|
||||
11
tests/fixtures/yaml_samples/edge_cases/negative_position.yaml
vendored
Normal file
11
tests/fixtures/yaml_samples/edge_cases/negative_position.yaml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
- type: text
|
||||
box: [-1, -1, 2, 1]
|
||||
content: "Negative Position"
|
||||
font:
|
||||
size: 18
|
||||
color: "#333333"
|
||||
10
tests/fixtures/yaml_samples/edge_cases/special_chars.yaml
vendored
Normal file
10
tests/fixtures/yaml_samples/edge_cases/special_chars.yaml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
- type: text
|
||||
box: [1, 1, 8, 2]
|
||||
content: "Special chars: < > & \" ' \\n \\t @#$%^&*()"
|
||||
font:
|
||||
size: 18
|
||||
10
tests/fixtures/yaml_samples/edge_cases/unicode.yaml
vendored
Normal file
10
tests/fixtures/yaml_samples/edge_cases/unicode.yaml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
- type: text
|
||||
box: [1, 1, 8, 1]
|
||||
content: "Unicode 测试: 你好世界 🌍"
|
||||
font:
|
||||
size: 24
|
||||
11
tests/fixtures/yaml_samples/edge_cases/very_large_font.yaml
vendored
Normal file
11
tests/fixtures/yaml_samples/edge_cases/very_large_font.yaml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
- type: text
|
||||
box: [0, 0, 1, 1]
|
||||
content: "Very Large Font"
|
||||
font:
|
||||
size: 200
|
||||
color: "#333333"
|
||||
10
tests/fixtures/yaml_samples/edge_cases/zero_size_box.yaml
vendored
Normal file
10
tests/fixtures/yaml_samples/edge_cases/zero_size_box.yaml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
- type: text
|
||||
box: [1, 1, 0, 0]
|
||||
content: "Zero Size Box"
|
||||
font:
|
||||
size: 18
|
||||
71
tests/fixtures/yaml_samples/full_features.yaml
vendored
Normal file
71
tests/fixtures/yaml_samples/full_features.yaml
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
# 文本元素幻灯片
|
||||
- background:
|
||||
color: "#ffffff"
|
||||
elements:
|
||||
- type: text
|
||||
box: [1, 1, 8, 1]
|
||||
content: "Full Features Test"
|
||||
font:
|
||||
size: 44
|
||||
bold: true
|
||||
color: "#333333"
|
||||
align: center
|
||||
|
||||
- type: text
|
||||
box: [1, 2.5, 8, 0.5]
|
||||
content: "Testing all element types"
|
||||
font:
|
||||
size: 18
|
||||
italic: true
|
||||
color: "#666666"
|
||||
align: center
|
||||
|
||||
# 图片元素幻灯片
|
||||
- elements:
|
||||
- type: image
|
||||
box: [1, 1, 4, 3]
|
||||
src: "test_image.png"
|
||||
|
||||
# 形状元素幻灯片
|
||||
- elements:
|
||||
- type: shape
|
||||
box: [1, 1, 2, 1]
|
||||
shape: rectangle
|
||||
fill: "#4a90e2"
|
||||
line:
|
||||
color: "#000000"
|
||||
width: 2
|
||||
|
||||
- type: shape
|
||||
box: [4, 1, 2, 1]
|
||||
shape: ellipse
|
||||
fill: "#e24a4a"
|
||||
line:
|
||||
color: "#000000"
|
||||
width: 1
|
||||
|
||||
- type: shape
|
||||
box: [7, 1, 2, 1]
|
||||
shape: rounded_rectangle
|
||||
fill: "#4ae290"
|
||||
line:
|
||||
color: "#000000"
|
||||
width: 2
|
||||
|
||||
# 表格元素幻灯片
|
||||
- elements:
|
||||
- type: table
|
||||
position: [1, 1]
|
||||
col_widths: [2, 2, 2]
|
||||
data:
|
||||
- ["Header 1", "Header 2", "Header 3"]
|
||||
- ["Data 1", "Data 2", "Data 3"]
|
||||
- ["Data 4", "Data 5", "Data 6"]
|
||||
style:
|
||||
font_size: 14
|
||||
header_bg: "#4a90e2"
|
||||
header_color: "#ffffff"
|
||||
11
tests/fixtures/yaml_samples/invalid/invalid_color.yaml
vendored
Normal file
11
tests/fixtures/yaml_samples/invalid/invalid_color.yaml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
- type: text
|
||||
box: [1, 1, 8, 1]
|
||||
content: "Invalid color"
|
||||
font:
|
||||
size: 18
|
||||
color: "red" # Should be #RRGGBB
|
||||
8
tests/fixtures/yaml_samples/invalid/missing_slides.yaml
vendored
Normal file
8
tests/fixtures/yaml_samples/invalid/missing_slides.yaml
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
# Missing 'slides' key
|
||||
elements:
|
||||
- type: text
|
||||
box: [1, 1, 8, 1]
|
||||
content: "No slides key"
|
||||
8
tests/fixtures/yaml_samples/invalid/syntax_error.yaml
vendored
Normal file
8
tests/fixtures/yaml_samples/invalid/syntax_error.yaml
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- elements:
|
||||
- type: text
|
||||
box: [1, 1, 8, 1
|
||||
content: "Missing closing bracket"
|
||||
15
tests/fixtures/yaml_samples/minimal.yaml
vendored
Normal file
15
tests/fixtures/yaml_samples/minimal.yaml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
metadata:
|
||||
size: 16:9
|
||||
|
||||
slides:
|
||||
- background:
|
||||
color: "#ffffff"
|
||||
elements:
|
||||
- type: text
|
||||
box: [1, 1, 8, 1]
|
||||
content: "Hello, World!"
|
||||
font:
|
||||
size: 44
|
||||
bold: true
|
||||
color: "#333333"
|
||||
align: center
|
||||
Reference in New Issue
Block a user