111 lines
2.8 KiB
Python
111 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
基础功能测试脚本
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def test_basic_imports():
|
|
"""测试基础模块导入"""
|
|
try:
|
|
# 测试基本枚举
|
|
from enum import Enum
|
|
print("✅ enum 导入成功")
|
|
|
|
# 测试 dataclass
|
|
from dataclasses import dataclass, field
|
|
print("✅ dataclass 导入成功")
|
|
|
|
# 测试路径操作
|
|
from datetime import datetime
|
|
print("✅ datetime 导入成功")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ 基础模块导入失败: {e}")
|
|
return False
|
|
|
|
def test_simple_dataclass():
|
|
"""测试简单数据类"""
|
|
try:
|
|
from dataclasses import dataclass, field
|
|
from typing import Optional, List
|
|
from enum import Enum
|
|
|
|
# 定义简单枚举
|
|
class TestEnum(Enum):
|
|
VALUE1 = "value1"
|
|
VALUE2 = "value2"
|
|
|
|
# 定义简单数据类
|
|
@dataclass
|
|
class SimpleClass:
|
|
name: str = field()
|
|
age: int = 0
|
|
optional_field: Optional[str] = None
|
|
|
|
# 测试实例化
|
|
obj = SimpleClass(name="测试", age=25)
|
|
print(f"✅ 简单数据类测试成功: {obj}")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ 简单数据类测试失败: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def test_platform_enum():
|
|
"""测试平台枚举"""
|
|
try:
|
|
from enum import Enum
|
|
|
|
class PlatformType(Enum):
|
|
XIAOHONGSHU = "xiaohongshu"
|
|
DOUYIN = "douyin"
|
|
|
|
print(f"✅ 平台枚举测试成功: {PlatformType.XIAOHONGSHU}")
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ 平台枚举测试失败: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""主测试函数"""
|
|
print("🚀 开始基础功能测试")
|
|
print("=" * 50)
|
|
|
|
tests = [
|
|
("基础模块导入", test_basic_imports),
|
|
("简单数据类", test_simple_dataclass),
|
|
("平台枚举", test_platform_enum),
|
|
]
|
|
|
|
passed = 0
|
|
total = len(tests)
|
|
|
|
for test_name, test_func in tests:
|
|
print(f"\n📋 测试: {test_name}")
|
|
try:
|
|
if test_func():
|
|
passed += 1
|
|
print(f"✅ {test_name} 通过")
|
|
else:
|
|
print(f"❌ {test_name} 失败")
|
|
except Exception as e:
|
|
print(f"❌ {test_name} 异常: {e}")
|
|
|
|
print("\n" + "=" * 50)
|
|
print(f"📊 测试结果: {passed}/{total} 通过")
|
|
|
|
if passed == total:
|
|
print("🎉 所有基础测试通过!")
|
|
return True
|
|
else:
|
|
print("⚠️ 部分测试失败")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1) |