1
0
Files
PPTX/tests/unit/test_utils.py
lanyuanxiaoyao f34405be36 feat: 移除图片适配模式功能
移除图片 fit 和 background 参数支持,简化图片渲染逻辑。系统恢复到直接使用 python-pptx 原生图片添加功能,图片将被拉伸到指定尺寸。

变更内容:
- 移除 ImageElement 的 fit 和 background 字段
- 移除 metadata.dpi 配置
- 删除 utils/image_utils.py 图片处理工具模块
- 删除 validators/image_config.py 验证器
- 简化 PPTX 和 HTML 渲染器的图片处理逻辑
- HTML 渲染器使用硬编码 DPI=96(Web 标准)
- 删除相关测试文件(单元测试、集成测试、e2e 测试)
- 更新规格文档和用户文档
- 保留 Pillow 依赖用于未来可能的图片处理需求

影响:
- 删除 11 个文件
- 修改 10 个文件
- 净减少 1558 行代码
- 所有 402 个测试通过

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-04 14:23:12 +08:00

55 lines
1.8 KiB
Python

"""
工具函数单元测试
测试颜色转换和格式验证函数
"""
import pytest
from utils import hex_to_rgb
class TestHexToRgb:
"""hex_to_rgb 函数测试类"""
def test_full_hex_format(self):
"""测试完整的 #RRGGBB 格式"""
assert hex_to_rgb("#ffffff") == (255, 255, 255)
assert hex_to_rgb("#000000") == (0, 0, 0)
assert hex_to_rgb("#4a90e2") == (74, 144, 226)
assert hex_to_rgb("#FF0000") == (255, 0, 0)
assert hex_to_rgb("#00FF00") == (0, 255, 0)
assert hex_to_rgb("#0000FF") == (0, 0, 255)
def test_short_hex_format(self):
"""测试短格式 #RGB"""
assert hex_to_rgb("#fff") == (255, 255, 255)
assert hex_to_rgb("#000") == (0, 0, 0)
assert hex_to_rgb("#abc") == (170, 187, 204)
assert hex_to_rgb("#ABC") == (170, 187, 204)
def test_without_hash_sign(self):
"""测试没有 # 号"""
assert hex_to_rgb("ffffff") == (255, 255, 255)
assert hex_to_rgb("4a90e2") == (74, 144, 226)
def test_invalid_length(self):
"""测试无效长度"""
with pytest.raises(ValueError, match="无效的颜色格式"):
hex_to_rgb("#ff") # 太短
with pytest.raises(ValueError, match="无效的颜色格式"):
hex_to_rgb("#fffff") # 5 位
with pytest.raises(ValueError, match="无效的颜色格式"):
hex_to_rgb("#fffffff") # 7 位
def test_invalid_characters(self):
"""测试无效字符"""
with pytest.raises(ValueError):
hex_to_rgb("#gggggg")
with pytest.raises(ValueError):
hex_to_rgb("#xyz")
def test_mixed_case(self):
"""测试大小写混合"""
assert hex_to_rgb("#AbCdEf") == (171, 205, 239)
assert hex_to_rgb("#aBcDeF") == (171, 205, 239)