78 lines
2.0 KiB
Python
78 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
模型定义测试脚本
|
|
"""
|
|
|
|
import sys
|
|
from dataclasses import dataclass, field
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
from typing import Optional, List, Dict, Any
|
|
from pathlib import Path
|
|
|
|
def test_model_definitions():
|
|
"""测试模型定义"""
|
|
try:
|
|
# 定义枚举
|
|
class PlatformType(Enum):
|
|
XIAOHONGSHU = "xiaohongshu"
|
|
DOUYIN = "douyin"
|
|
|
|
# 定义基类 - 所有参数都没有默认值
|
|
@dataclass
|
|
class Content:
|
|
title: str
|
|
description: str
|
|
tags: List[str] = field(default_factory=list)
|
|
visibility: str = "public"
|
|
|
|
@dataclass
|
|
class ImageNote(Content):
|
|
images: List[str] = field(default_factory=list)
|
|
cover_image: Optional[str] = None
|
|
|
|
@dataclass
|
|
class VideoContent(Content):
|
|
video_path: str
|
|
cover_image: Optional[str] = None
|
|
|
|
# 测试实例化
|
|
note = ImageNote(
|
|
title="测试标题",
|
|
description="测试描述",
|
|
images=["test1.jpg", "test2.jpg"]
|
|
)
|
|
|
|
video = VideoContent(
|
|
title="视频标题",
|
|
description="视频描述",
|
|
video_path="test.mp4"
|
|
)
|
|
|
|
print(f"✅ 图文笔记: {note.title}")
|
|
print(f"✅ 视频内容: {video.title}")
|
|
print(f"✅ 平台类型: {PlatformType.XIAOHONGSHU}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ 模型定义测试失败: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def main():
|
|
"""主测试函数"""
|
|
print("🚀 开始模型定义测试")
|
|
print("=" * 50)
|
|
|
|
if test_model_definitions():
|
|
print("\n🎉 模型定义测试通过!")
|
|
return True
|
|
else:
|
|
print("\n❌ 模型定义测试失败!")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1) |