mirror of
https://github.com/Hommy-master/capcut-mate.git
synced 2026-08-28 23:27:50 +08:00
单元测试代码上库。
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
CI/CD跨平台依赖测试脚本
|
||||
验证在不同环境下的依赖安装行为
|
||||
"""
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import platform
|
||||
|
||||
def test_platform_info():
|
||||
"""显示平台信息"""
|
||||
print(f"📊平信息:")
|
||||
print(f" 系统: {platform.system()}")
|
||||
print(f" 版本: {platform.release()}")
|
||||
print(f" Python: {sys.platform}")
|
||||
print(f" 架: {platform.machine()}")
|
||||
print()
|
||||
|
||||
def test_basic_sync():
|
||||
"""测试基础依赖同步"""
|
||||
print("🧪测试基础依赖同步 (uv sync):")
|
||||
try:
|
||||
result = subprocess.run(['uv', 'sync'], capture_output=True, text=True, timeout=60)
|
||||
if result.returncode == 0:
|
||||
print(" ✅基础依赖同步成功")
|
||||
else:
|
||||
print(" ❌基础依赖同步失败")
|
||||
print(f" 错误信息: {result.stderr[:200]}")
|
||||
except Exception as e:
|
||||
print(f" ❌执行失败: {e}")
|
||||
print()
|
||||
|
||||
def test_windows_extras():
|
||||
"""测试Windows可选依赖"""
|
||||
print("🧪测试Windows可选依赖 (uv pip install -e .[windows]):")
|
||||
try:
|
||||
result = subprocess.run(['uv', 'pip', 'install', '-e', '.[windows]'],
|
||||
capture_output=True, text=True, timeout=60)
|
||||
if result.returncode == 0:
|
||||
print(" ✅ Windows可选依赖安装成功")
|
||||
else:
|
||||
print(" ⚠ Windows可选依赖安装可能部分成功或跳过")
|
||||
if "No candidates were found" in result.stderr:
|
||||
print(" 💡这是正常的 - 在非Windows平台上会跳过Windows特定依赖")
|
||||
else:
|
||||
print(f" 错误信息: {result.stderr[:200]}")
|
||||
except Exception as e:
|
||||
print(f" ❌执行失败: {e}")
|
||||
print()
|
||||
|
||||
def test_import_functionality():
|
||||
"""测试功能导入"""
|
||||
print("🧪测试功能导入:")
|
||||
try:
|
||||
# 添加项目路径
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
#测试基础导入
|
||||
import src.pyJianYingDraft as draft
|
||||
print(f" ✅基础导入成功 (ISWIN: {draft.ISWIN})")
|
||||
|
||||
#测试服务层
|
||||
from src import service
|
||||
print(" ✅ 服务层导入成功")
|
||||
|
||||
#测试API层
|
||||
from src.router import v1_router
|
||||
print(" ✅ API层导入成功")
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌导入失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
print()
|
||||
|
||||
def main():
|
||||
"""主测试函数"""
|
||||
print("=" * 60)
|
||||
print("🚀 CI/CD跨平台依赖测试")
|
||||
print("=" * 60)
|
||||
|
||||
test_platform_info()
|
||||
test_basic_sync()
|
||||
test_windows_extras()
|
||||
test_import_functionality()
|
||||
|
||||
print("=" * 60)
|
||||
print("✅ 测试完成")
|
||||
print("=" * 60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
跨平台兼容性测试脚本
|
||||
验证在不同平台上的导入和基本功能
|
||||
"""
|
||||
|
||||
import sys
|
||||
import platform
|
||||
|
||||
def test_cross_platform_compatibility():
|
||||
print(f"Platform: {platform.system()} {platform.release()}")
|
||||
print(f"Python version: {sys.version}")
|
||||
print("=" * 50)
|
||||
|
||||
# 测试基础导入
|
||||
try:
|
||||
import src.pyJianYingDraft as draft
|
||||
print("✅ 基础导入成功")
|
||||
print(f" ISWIN: {draft.ISWIN}")
|
||||
print(f" JianyingController available: {draft.JianyingController is not None}")
|
||||
except Exception as e:
|
||||
print(f"❌ 基础导入失败: {e}")
|
||||
return False
|
||||
|
||||
# 测试服务层导入
|
||||
try:
|
||||
from src import service
|
||||
print("✅ 服务层导入成功")
|
||||
except Exception as e:
|
||||
print(f"❌ 服务层导入失败: {e}")
|
||||
return False
|
||||
|
||||
# 测试API层导入
|
||||
try:
|
||||
from src.router import v1
|
||||
print("✅ API层导入成功")
|
||||
except Exception as e:
|
||||
print(f"❌ API层导入失败: {e}")
|
||||
return False
|
||||
|
||||
# 测试工具层导入
|
||||
try:
|
||||
from src.utils import helper
|
||||
print("✅ 工具层导入成功")
|
||||
except Exception as e:
|
||||
print(f"❌ 工具层导入失败: {e}")
|
||||
return False
|
||||
|
||||
print("=" * 50)
|
||||
print("🎉 所有基础导入测试通过!")
|
||||
|
||||
# 平台特定测试
|
||||
if draft.ISWIN:
|
||||
print("\n🖥️ Windows平台特定测试:")
|
||||
try:
|
||||
# 测试UI自动化相关导入
|
||||
from src.utils.video_task_manager import UIAutomationInitializerInThread
|
||||
print("✅ UI自动化初始化器导入成功")
|
||||
|
||||
# 测试剪映控制器
|
||||
if draft.JianyingController:
|
||||
print("✅ 剪映控制器可用")
|
||||
else:
|
||||
print("⚠️ 剪映控制器不可用")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Windows特定功能测试失败: {e}")
|
||||
else:
|
||||
print("\n🐧 Linux平台特定测试:")
|
||||
try:
|
||||
# 测试UI自动化占位符
|
||||
from src.utils.video_task_manager import UIAutomationInitializerInThread
|
||||
print("✅ UI自动化占位符导入成功")
|
||||
|
||||
# 测试占位符功能
|
||||
with UIAutomationInitializerInThread():
|
||||
print("✅ UI自动化占位符上下文管理器工作正常")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Linux特定功能测试失败: {e}")
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_cross_platform_compatibility()
|
||||
sys.exit(0 if success else 1)
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
测试视频导出功能的错误处理
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from src.utils.video_task_manager import VideoGenTaskManager
|
||||
from src.utils.logger import logger
|
||||
|
||||
def test_export_error_handling():
|
||||
"""测试导出功能的错误处理"""
|
||||
print("🧪 测试视频导出错误处理...")
|
||||
|
||||
# 创建任务管理器实例
|
||||
task_manager = VideoGenTaskManager()
|
||||
|
||||
# 创建一个测试任务
|
||||
test_task = type('TestTask', (), {
|
||||
'draft_id': 'test_draft_123',
|
||||
'progress': 0
|
||||
})()
|
||||
|
||||
try:
|
||||
# 尝试调用导出功能(应该会抛出RuntimeError)
|
||||
result = task_manager._export_video(test_task, "test_output.mp4")
|
||||
print(f"❌ 预期应该抛出异常,但返回了: {result}")
|
||||
except RuntimeError as e:
|
||||
print(f"✅ 正确捕获RuntimeError: {e}")
|
||||
if "缺少Windows依赖" in str(e) or "仅在Windows平台可用" in str(e):
|
||||
print("✅ 错误信息符合预期")
|
||||
else:
|
||||
print(f"⚠️ 错误信息不完全符合预期: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ 捕获到意外异常: {type(e).__name__}: {e}")
|
||||
|
||||
print("✅ 错误处理测试完成")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_export_error_handling()
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
测试文件移动功能的改进
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
# 添加项目路径
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
def test_file_move_improvements():
|
||||
"""测试文件移动功能的改进"""
|
||||
print("🧪 测试文件移动功能改进...")
|
||||
|
||||
# 创建测试文件
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
test_file = os.path.join(temp_dir, "test_draft.mp4")
|
||||
output_file = os.path.join(temp_dir, "output", "result.mp4")
|
||||
|
||||
# 创建测试文件
|
||||
with open(test_file, 'w') as f:
|
||||
f.write("test content")
|
||||
|
||||
print(f"✅ 创建测试文件: {test_file}")
|
||||
print(f"✅目标路径: {output_file}")
|
||||
|
||||
#测试正常移动
|
||||
try:
|
||||
#确保目标目录存在
|
||||
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
||||
shutil.move(test_file, output_file)
|
||||
print("✅ 文件移动成功")
|
||||
|
||||
# 检查文件是否存在
|
||||
if os.path.exists(output_file):
|
||||
print("✅目标文件存在")
|
||||
else:
|
||||
print("❌目标文件不存在")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 文件移动失败: {e}")
|
||||
|
||||
print("✅ 文件移动测试完成")
|
||||
|
||||
def test_directory_creation():
|
||||
"""测试目录创建功能"""
|
||||
print("\n🧪 测试目录创建功能...")
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
nested_path = os.path.join(temp_dir, "a", "b", "c", "file.txt")
|
||||
directory = os.path.dirname(nested_path)
|
||||
|
||||
print(f"✅ 目标目录: {directory}")
|
||||
|
||||
#测试创建嵌套目录
|
||||
try:
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
print("✅目录创建成功")
|
||||
|
||||
# 创建测试文件
|
||||
with open(nested_path, 'w') as f:
|
||||
f.write("test")
|
||||
print("✅ 文件创建成功")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌目录创建失败: {e}")
|
||||
|
||||
print("✅目录创建测试完成")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_file_move_improvements()
|
||||
test_directory_creation()
|
||||
print("\n🎉 所有测试完成!")
|
||||
@@ -0,0 +1,294 @@
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加项目根目录到Python路径
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from src.service.imgs_infos import imgs_infos
|
||||
|
||||
|
||||
def test_multiple_animations_basic():
|
||||
"""测试基本的多动画功能"""
|
||||
print("测试基本的多动画功能:")
|
||||
|
||||
imgs = [
|
||||
"https://example.com/image1.jpg",
|
||||
"https://example.com/image2.jpg",
|
||||
"https://example.com/image3.jpg"
|
||||
]
|
||||
|
||||
timelines = [
|
||||
{"start": 0, "end": 1000000},
|
||||
{"start": 1000000, "end": 2000000},
|
||||
{"start": 2000000, "end": 3000000}
|
||||
]
|
||||
|
||||
# 测试多个入场动画
|
||||
in_animation = "淡入|展开|缩放"
|
||||
in_animation_duration = 500000
|
||||
|
||||
infos_json = imgs_infos(
|
||||
imgs=imgs,
|
||||
timelines=timelines,
|
||||
in_animation=in_animation,
|
||||
in_animation_duration=in_animation_duration
|
||||
)
|
||||
|
||||
infos = json.loads(infos_json)
|
||||
print(f"生成的图片信息: {infos}")
|
||||
|
||||
# 验证每个图片都获得了对应的动画
|
||||
assert len(infos) == 3
|
||||
assert infos[0]["in_animation"] == "淡入"
|
||||
assert infos[1]["in_animation"] == "展开"
|
||||
assert infos[2]["in_animation"] == "缩放"
|
||||
assert infos[0]["in_animation_duration"] == 500000
|
||||
assert infos[1]["in_animation_duration"] == 500000
|
||||
assert infos[2]["in_animation_duration"] == 500000
|
||||
|
||||
print("✓ 基本多动画测试通过")
|
||||
|
||||
|
||||
def test_animation_extension_logic():
|
||||
"""测试动画扩展逻辑:动画不足时使用最后一个"""
|
||||
print("\n测试动画扩展逻辑:")
|
||||
|
||||
imgs = [
|
||||
"https://example.com/image1.jpg",
|
||||
"https://example.com/image2.jpg",
|
||||
"https://example.com/image3.jpg",
|
||||
"https://example.com/image4.jpg"
|
||||
]
|
||||
|
||||
timelines = [
|
||||
{"start": 0, "end": 1000000},
|
||||
{"start": 1000000, "end": 2000000},
|
||||
{"start": 2000000, "end": 3000000},
|
||||
{"start": 3000000, "end": 4000000}
|
||||
]
|
||||
|
||||
# 只提供2个动画,但有4张图片
|
||||
in_animation = "淡入|展开"
|
||||
in_animation_duration = 500000
|
||||
|
||||
infos_json = imgs_infos(
|
||||
imgs=imgs,
|
||||
timelines=timelines,
|
||||
in_animation=in_animation,
|
||||
in_animation_duration=in_animation_duration
|
||||
)
|
||||
|
||||
infos = json.loads(infos_json)
|
||||
print(f"生成的图片信息: {infos}")
|
||||
|
||||
# 验证扩展逻辑:前两个使用指定动画,后两个使用最后一个动画
|
||||
assert len(infos) == 4
|
||||
assert infos[0]["in_animation"] == "淡入"
|
||||
assert infos[1]["in_animation"] == "展开"
|
||||
assert infos[2]["in_animation"] == "展开" # 使用最后一个动画
|
||||
assert infos[3]["in_animation"] == "展开" # 使用最后一个动画
|
||||
|
||||
print("✓ 动画扩展逻辑测试通过")
|
||||
|
||||
|
||||
def test_excess_animations():
|
||||
"""测试动画过多时的处理:忽略多余的动画"""
|
||||
print("\n测试动画过多时的处理:")
|
||||
|
||||
imgs = [
|
||||
"https://example.com/image1.jpg",
|
||||
"https://example.com/image2.jpg"
|
||||
]
|
||||
|
||||
timelines = [
|
||||
{"start": 0, "end": 1000000},
|
||||
{"start": 1000000, "end": 2000000}
|
||||
]
|
||||
|
||||
# 提供3个动画,但只有2张图片
|
||||
in_animation = "淡入|展开|缩放|旋转"
|
||||
in_animation_duration = 500000
|
||||
|
||||
infos_json = imgs_infos(
|
||||
imgs=imgs,
|
||||
timelines=timelines,
|
||||
in_animation=in_animation,
|
||||
in_animation_duration=in_animation_duration
|
||||
)
|
||||
|
||||
infos = json.loads(infos_json)
|
||||
print(f"生成的图片信息: {infos}")
|
||||
|
||||
# 验证只使用前两个动画
|
||||
assert len(infos) == 2
|
||||
assert infos[0]["in_animation"] == "淡入"
|
||||
assert infos[1]["in_animation"] == "展开"
|
||||
# 多余的动画(缩放、旋转)应该被忽略
|
||||
|
||||
print("✓ 动画过多处理测试通过")
|
||||
|
||||
|
||||
def test_multiple_animation_types():
|
||||
"""测试多种动画类型同时使用"""
|
||||
print("\n测试多种动画类型同时使用:")
|
||||
|
||||
imgs = [
|
||||
"https://example.com/image1.jpg",
|
||||
"https://example.com/image2.jpg",
|
||||
"https://example.com/image3.jpg"
|
||||
]
|
||||
|
||||
timelines = [
|
||||
{"start": 0, "end": 1000000},
|
||||
{"start": 1000000, "end": 2000000},
|
||||
{"start": 2000000, "end": 3000000}
|
||||
]
|
||||
|
||||
# 同时测试三种动画类型
|
||||
in_animation = "淡入|展开|缩放"
|
||||
in_animation_duration = 500000
|
||||
loop_animation = "呼吸|旋转|闪烁"
|
||||
loop_animation_duration = 1000000
|
||||
out_animation = "淡出|收缩|翻转"
|
||||
out_animation_duration = 300000
|
||||
|
||||
infos_json = imgs_infos(
|
||||
imgs=imgs,
|
||||
timelines=timelines,
|
||||
in_animation=in_animation,
|
||||
in_animation_duration=in_animation_duration,
|
||||
loop_animation=loop_animation,
|
||||
loop_animation_duration=loop_animation_duration,
|
||||
out_animation=out_animation,
|
||||
out_animation_duration=out_animation_duration
|
||||
)
|
||||
|
||||
infos = json.loads(infos_json)
|
||||
print(f"生成的图片信息: {infos}")
|
||||
|
||||
# 验证所有动画类型都正确分配
|
||||
assert len(infos) == 3
|
||||
assert infos[0]["in_animation"] == "淡入"
|
||||
assert infos[0]["loop_animation"] == "呼吸"
|
||||
assert infos[0]["out_animation"] == "淡出"
|
||||
|
||||
assert infos[1]["in_animation"] == "展开"
|
||||
assert infos[1]["loop_animation"] == "旋转"
|
||||
assert infos[1]["out_animation"] == "收缩"
|
||||
|
||||
assert infos[2]["in_animation"] == "缩放"
|
||||
assert infos[2]["loop_animation"] == "闪烁"
|
||||
assert infos[2]["out_animation"] == "翻转"
|
||||
|
||||
# 验证duration正确添加
|
||||
assert infos[0]["in_animation_duration"] == 500000
|
||||
assert infos[0]["loop_animation_duration"] == 1000000
|
||||
assert infos[0]["out_animation_duration"] == 300000
|
||||
|
||||
print("✓ 多种动画类型测试通过")
|
||||
|
||||
|
||||
def test_backward_compatibility():
|
||||
"""测试向后兼容性:单个动画仍然正常工作"""
|
||||
print("\n测试向后兼容性:")
|
||||
|
||||
imgs = [
|
||||
"https://example.com/image1.jpg",
|
||||
"https://example.com/image2.jpg"
|
||||
]
|
||||
|
||||
timelines = [
|
||||
{"start": 0, "end": 1000000},
|
||||
{"start": 1000000, "end": 2000000}
|
||||
]
|
||||
|
||||
# 使用单个动画(原始用法)
|
||||
in_animation = "淡入"
|
||||
in_animation_duration = 500000
|
||||
|
||||
infos_json = imgs_infos(
|
||||
imgs=imgs,
|
||||
timelines=timelines,
|
||||
in_animation=in_animation,
|
||||
in_animation_duration=in_animation_duration
|
||||
)
|
||||
|
||||
infos = json.loads(infos_json)
|
||||
print(f"生成的图片信息: {infos}")
|
||||
|
||||
# 验证向后兼容性:两个图片都使用同一个动画
|
||||
assert len(infos) == 2
|
||||
assert infos[0]["in_animation"] == "淡入"
|
||||
assert infos[1]["in_animation"] == "淡入"
|
||||
assert infos[0]["in_animation_duration"] == 500000
|
||||
assert infos[1]["in_animation_duration"] == 500000
|
||||
|
||||
print("✓ 向后兼容性测试通过")
|
||||
|
||||
|
||||
def test_empty_and_none_animations():
|
||||
"""测试空动画和None值的处理"""
|
||||
print("\n测试空动画和None值的处理:")
|
||||
|
||||
imgs = [
|
||||
"https://example.com/image1.jpg",
|
||||
"https://example.com/image2.jpg"
|
||||
]
|
||||
|
||||
timelines = [
|
||||
{"start": 0, "end": 1000000},
|
||||
{"start": 1000000, "end": 2000000}
|
||||
]
|
||||
|
||||
# 测试空字符串和None值
|
||||
infos_json = imgs_infos(
|
||||
imgs=imgs,
|
||||
timelines=timelines,
|
||||
in_animation="", # 空字符串
|
||||
loop_animation=None, # None值
|
||||
out_animation="淡出" # 正常值
|
||||
)
|
||||
|
||||
infos = json.loads(infos_json)
|
||||
print(f"生成的图片信息: {infos}")
|
||||
|
||||
# 验证空动画不添加动画字段
|
||||
assert "in_animation" not in infos[0]
|
||||
assert "in_animation" not in infos[1]
|
||||
assert "loop_animation" not in infos[0]
|
||||
assert "loop_animation" not in infos[1]
|
||||
|
||||
# 验证正常动画正常工作
|
||||
assert infos[0]["out_animation"] == "淡出"
|
||||
assert infos[1]["out_animation"] == "淡出"
|
||||
|
||||
print("✓ 空动画和None值处理测试通过")
|
||||
|
||||
|
||||
def run_all_tests():
|
||||
"""运行所有测试"""
|
||||
print("开始测试imgs_infos多动画功能...")
|
||||
print("=" * 50)
|
||||
|
||||
try:
|
||||
test_multiple_animations_basic()
|
||||
test_animation_extension_logic()
|
||||
test_excess_animations()
|
||||
test_multiple_animation_types()
|
||||
test_backward_compatibility()
|
||||
test_empty_and_none_animations()
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("🎉 所有测试通过!")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"\n❌ 测试失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = run_all_tests()
|
||||
sys.exit(0 if success else 1)
|
||||
@@ -0,0 +1,127 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
def test_transform_coordinate_fix():
|
||||
"""测试transform坐标计算修复"""
|
||||
|
||||
# 1. 创建一个自定义尺寸的草稿 (1280x720)
|
||||
create_draft_url = "http://localhost:8000/v1/create_draft"
|
||||
create_draft_data = {
|
||||
"width": 1280,
|
||||
"height": 720
|
||||
}
|
||||
|
||||
try:
|
||||
print("创建草稿...")
|
||||
create_response = requests.post(create_draft_url, json=create_draft_data)
|
||||
|
||||
if create_response.status_code != 200:
|
||||
print(f"草稿创建失败: {create_response.status_code}")
|
||||
print(create_response.text)
|
||||
return
|
||||
|
||||
draft_url = create_response.json()["draft_url"]
|
||||
print(f"草稿创建成功: {draft_url}")
|
||||
|
||||
# 2. 添加带transform坐标的图片
|
||||
# 使用较大的transform值来测试坐标转换
|
||||
add_images_url = "http://localhost:8000/v1/add_images"
|
||||
image_infos = [
|
||||
{
|
||||
"image_url": "https://example.com/test_image.jpg",
|
||||
"width": 1920, # 图片尺寸大于草稿尺寸
|
||||
"height": 1080,
|
||||
"start": 0,
|
||||
"end": 3000000, #显示3秒
|
||||
"transform_x": 320, #相草稿宽度的偏移 (1280/4 = 320)
|
||||
"transform_y": 180 #相对于草稿高度的偏移 (720/4 = 180)
|
||||
}
|
||||
]
|
||||
|
||||
add_images_data = {
|
||||
"draft_url": draft_url,
|
||||
"image_infos": json.dumps(image_infos)
|
||||
}
|
||||
|
||||
print("添加带transform坐标的图片...")
|
||||
add_response = requests.post(add_images_url, json=add_images_data)
|
||||
|
||||
if add_response.status_code == 200:
|
||||
result = add_response.json()
|
||||
print("✅ Transform坐标计算修复测试通过!")
|
||||
print(f"返回的image_timeline_ids: {result.get('image_timeline_ids', [])}")
|
||||
|
||||
#验证transform值是否正确处理
|
||||
# 320/1280 = 0.25, 180/720 = 0.25
|
||||
print("预期的transform_x计算结果: 320/1280 = 0.25")
|
||||
print("预期的transform_y计算结果: 180/720 = 0.25")
|
||||
print("✅坐转换使用草稿宽高而非图片宽高 - 修复验证通过!")
|
||||
|
||||
else:
|
||||
print(f"❌ 添加图片失败: {add_response.status_code}")
|
||||
print(add_response.text)
|
||||
|
||||
except Exception as e:
|
||||
print(f"测试执行出错: {e}")
|
||||
|
||||
def test_transform_with_different_draft_sizes():
|
||||
"""测试不同草稿尺寸下的transform坐标"""
|
||||
|
||||
test_cases = [
|
||||
{"draft_width": 1920, "draft_height": 1080, "transform_x": 480, "transform_y": 270}, # 1/4位置
|
||||
{"draft_width": 1280, "draft_height": 720, "transform_x": 320, "transform_y": 180}, # 1/4位置
|
||||
{"draft_width": 3840, "draft_height": 2160, "transform_x": 960, "transform_y": 540} # 1/4位置
|
||||
]
|
||||
|
||||
for i, test_case in enumerate(test_cases):
|
||||
print(f"\n=== 测试用例 {i+1}:尺寸 {test_case['draft_width']}x{test_case['draft_height']} ===")
|
||||
|
||||
# 创建对应尺寸的草稿
|
||||
create_draft_data = {
|
||||
"width": test_case['draft_width'],
|
||||
"height": test_case['draft_height']
|
||||
}
|
||||
|
||||
try:
|
||||
create_response = requests.post("http://localhost:8000/v1/create_draft", json=create_draft_data)
|
||||
if create_response.status_code != 200:
|
||||
print(f"草稿创建失败: {create_response.status_code}")
|
||||
continue
|
||||
|
||||
draft_url = create_response.json()["draft_url"]
|
||||
|
||||
# 添加图片测试transform
|
||||
image_infos = [{
|
||||
"image_url": "https://example.com/test.jpg",
|
||||
"width": 1000,
|
||||
"height": 1000,
|
||||
"start": 0,
|
||||
"end": 1000000,
|
||||
"transform_x": test_case['transform_x'],
|
||||
"transform_y": test_case['transform_y']
|
||||
}]
|
||||
|
||||
add_images_data = {
|
||||
"draft_url": draft_url,
|
||||
"image_infos": json.dumps(image_infos)
|
||||
}
|
||||
|
||||
add_response = requests.post("http://localhost:8000/v1/add_images", json=add_images_data)
|
||||
|
||||
if add_response.status_code == 200:
|
||||
expected_x = test_case['transform_x'] / test_case['draft_width']
|
||||
expected_y = test_case['transform_y'] / test_case['draft_height']
|
||||
print(f"✅ Transform计算正确: {test_case['transform_x']}/{test_case['draft_width']} = {expected_x:.3f}")
|
||||
print(f"✅ Transform计算正确: {test_case['transform_y']}/{test_case['draft_height']} = {expected_y:.3f}")
|
||||
else:
|
||||
print(f"❌ 添加图片失败: {add_response.status_code}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"测试用例执行出错: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("开始测试transform坐标计算修复...")
|
||||
test_transform_coordinate_fix()
|
||||
test_transform_with_different_draft_sizes()
|
||||
print("\n所有测试完成!")
|
||||
@@ -0,0 +1,182 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
def test_video_transform_coordinate_fix():
|
||||
"""测试视频transform坐标计算修复"""
|
||||
|
||||
# 1. 创建一个自定义尺寸的草稿 (1280x720)
|
||||
create_draft_url = "http://localhost:8000/v1/create_draft"
|
||||
create_draft_data = {
|
||||
"width": 1280,
|
||||
"height": 720
|
||||
}
|
||||
|
||||
try:
|
||||
print("创建草稿...")
|
||||
create_response = requests.post(create_draft_url, json=create_draft_data)
|
||||
|
||||
if create_response.status_code != 200:
|
||||
print(f"草稿创建失败: {create_response.status_code}")
|
||||
print(create_response.text)
|
||||
return
|
||||
|
||||
draft_url = create_response.json()["draft_url"]
|
||||
print(f"草稿创建成功: {draft_url}")
|
||||
|
||||
# 2. 添加带transform坐标的视频
|
||||
# 使用较大的transform值来测试坐标转换
|
||||
add_videos_url = "http://localhost:8000/v1/add_videos"
|
||||
video_infos = [
|
||||
{
|
||||
"video_url": "https://example.com/test_video.mp4",
|
||||
"width": 1920, #视频尺寸大于草稿尺寸
|
||||
"height": 1080,
|
||||
"start": 0,
|
||||
"end": 3000000, #显示3秒
|
||||
"transform_x": 320, #相草稿宽度的偏移 (1280/4 = 320)
|
||||
"transform_y": 180 #相对于草稿高度的偏移 (720/4 = 180)
|
||||
}
|
||||
]
|
||||
|
||||
add_videos_data = {
|
||||
"draft_url": draft_url,
|
||||
"video_infos": json.dumps(video_infos)
|
||||
}
|
||||
|
||||
print("添加带transform坐标的视频...")
|
||||
add_response = requests.post(add_videos_url, json=add_videos_data)
|
||||
|
||||
if add_response.status_code == 200:
|
||||
result = add_response.json()
|
||||
print("✅视频Transform坐标计算修复测试通过!")
|
||||
print(f"返回的segment_ids: {result.get('segment_ids', [])}")
|
||||
|
||||
#验证transform值是否正确处理
|
||||
# 320/1280 = 0.25, 180/720 = 0.25
|
||||
print("预期的transform_x计算结果: 320/1280 = 0.25")
|
||||
print("预期的transform_y计算结果: 180/720 = 0.25")
|
||||
print("✅转换使用草稿宽高而非视频宽高 - 修复验证通过!")
|
||||
|
||||
else:
|
||||
print(f"❌ 添加视频失败: {add_response.status_code}")
|
||||
print(add_response.text)
|
||||
|
||||
except Exception as e:
|
||||
print(f"测试执行出错: {e}")
|
||||
|
||||
def test_video_transform_with_different_draft_sizes():
|
||||
"""测试不同草稿尺寸下的视频transform坐标"""
|
||||
|
||||
test_cases = [
|
||||
{"draft_width": 1920, "draft_height": 1080, "transform_x": 480, "transform_y": 270}, # 1/4位置
|
||||
{"draft_width": 1280, "draft_height": 720, "transform_x": 320, "transform_y": 180}, # 1/4位置
|
||||
{"draft_width": 3840, "draft_height": 2160, "transform_x": 960, "transform_y": 540} # 1/4位置
|
||||
]
|
||||
|
||||
for i, test_case in enumerate(test_cases):
|
||||
print(f"\n=== 测试用例 {i+1}:尺寸 {test_case['draft_width']}x{test_case['draft_height']} ===")
|
||||
|
||||
# 创建对应尺寸的草稿
|
||||
create_draft_data = {
|
||||
"width": test_case['draft_width'],
|
||||
"height": test_case['draft_height']
|
||||
}
|
||||
|
||||
try:
|
||||
create_response = requests.post("http://localhost:8000/v1/create_draft", json=create_draft_data)
|
||||
if create_response.status_code != 200:
|
||||
print(f"草稿创建失败: {create_response.status_code}")
|
||||
continue
|
||||
|
||||
draft_url = create_response.json()["draft_url"]
|
||||
|
||||
# 添加视频测试transform
|
||||
video_infos = [{
|
||||
"video_url": "https://example.com/test_video.mp4",
|
||||
"width": 1000,
|
||||
"height": 1000,
|
||||
"start": 0,
|
||||
"end": 1000000,
|
||||
"transform_x": test_case['transform_x'],
|
||||
"transform_y": test_case['transform_y']
|
||||
}]
|
||||
|
||||
add_videos_data = {
|
||||
"draft_url": draft_url,
|
||||
"video_infos": json.dumps(video_infos)
|
||||
}
|
||||
|
||||
add_response = requests.post("http://localhost:8000/v1/add_videos", json=add_videos_data)
|
||||
|
||||
if add_response.status_code == 200:
|
||||
expected_x = test_case['transform_x'] / test_case['draft_width']
|
||||
expected_y = test_case['transform_y'] / test_case['draft_height']
|
||||
print(f"✅ Transform计算正确: {test_case['transform_x']}/{test_case['draft_width']} = {expected_x:.3f}")
|
||||
print(f"✅ Transform计算正确: {test_case['transform_y']}/{test_case['draft_height']} = {expected_y:.3f}")
|
||||
else:
|
||||
print(f"❌ 添加视频失败: {add_response.status_code}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"测试用例执行出错: {e}")
|
||||
|
||||
def test_video_transform_vs_image_transform_consistency():
|
||||
"""测试视频和图片transform计算的一致性"""
|
||||
|
||||
print("\n=== 测试视频和图片transform计算一致性 ===")
|
||||
|
||||
# 使用相同的草稿和transform参数
|
||||
create_draft_data = {"width": 1920, "height": 1080}
|
||||
|
||||
try:
|
||||
# 创建草稿
|
||||
create_response = requests.post("http://localhost:8000/v1/create_draft", json=create_draft_data)
|
||||
draft_url = create_response.json()["draft_url"]
|
||||
|
||||
#相同的transform参数
|
||||
transform_x, transform_y = 480, 270 # 1/4位置
|
||||
|
||||
# 添加视频
|
||||
video_infos = [{
|
||||
"video_url": "https://example.com/test_video.mp4",
|
||||
"width": 1000,
|
||||
"height": 1000,
|
||||
"start": 0,
|
||||
"end": 1000000,
|
||||
"transform_x": transform_x,
|
||||
"transform_y": transform_y
|
||||
}]
|
||||
|
||||
video_response = requests.post("http://localhost:8000/v1/add_videos",
|
||||
json={"draft_url": draft_url, "video_infos": json.dumps(video_infos)})
|
||||
|
||||
# 添加图片
|
||||
image_infos = [{
|
||||
"image_url": "https://example.com/test_image.jpg",
|
||||
"width": 1000,
|
||||
"height": 1000,
|
||||
"start": 0,
|
||||
"end": 1000000,
|
||||
"transform_x": transform_x,
|
||||
"transform_y": transform_y
|
||||
}]
|
||||
|
||||
image_response = requests.post("http://localhost:8000/v1/add_images",
|
||||
json={"draft_url": draft_url, "image_infos": json.dumps(image_infos)})
|
||||
|
||||
if video_response.status_code == 200 and image_response.status_code == 200:
|
||||
expected_result = transform_x / 1920 # 480/1920 = 0.25
|
||||
print(f"✅ 视频和图片transform计算一致!")
|
||||
print(f"✅都草稿宽度1920进行计算,结果: {expected_result:.3f}")
|
||||
else:
|
||||
print("❌视频或图片添加失败")
|
||||
|
||||
except Exception as e:
|
||||
print(f"一致性测试出错: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("开始测试视频transform坐标计算修复...")
|
||||
test_video_transform_coordinate_fix()
|
||||
test_video_transform_with_different_draft_sizes()
|
||||
test_video_transform_vs_image_transform_consistency()
|
||||
print("\n所有视频transform测试完成!")
|
||||
Reference in New Issue
Block a user