Files
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

109 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""
测试图片生成技能
"""
import sys
import os
# 添加当前目录到路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from image_generation import (
create_chart,
create_qrcode,
text_to_image,
create_system_status
)
def test_chart():
print("测试图表生成...")
data = {
'labels': ['Python', 'JavaScript', 'Java', 'C++', 'Go'],
'values': [85, 90, 75, 60, 55]
}
try:
path = create_chart(data, chart_type='bar', title='编程语言流行度')
print(f"✅ 图表生成成功: {path}")
return True
except Exception as e:
print(f"❌ 图表生成失败: {e}")
return False
def test_qrcode():
print("测试二维码生成...")
try:
path = create_qrcode('https://github.com/nanobot-ai/nanobot', size=200)
print(f"✅ 二维码生成成功: {path}")
return True
except Exception as e:
print(f"❌ 二维码生成失败: {e}")
return False
def test_text_image():
print("测试文本转图片...")
try:
path = text_to_image('Hello nanobot!\nImage Generation Test\n2026-03-13')
print(f"✅ 文本转图片成功: {path}")
return True
except Exception as e:
print(f"❌ 文本转图片失败: {e}")
return False
def test_system_status():
print("测试系统状态图...")
status_data = {
'CPU Usage': 42,
'Memory': 68,
'Disk Space': 78,
'Network': 'Online',
'Service': 'Running'
}
try:
path = create_system_status(status_data)
print(f"✅ 系统状态图生成成功: {path}")
return True
except Exception as e:
print(f"❌ 系统状态图生成失败: {e}")
return False
def main():
print("=" * 60)
print("Image Generation Skill 测试")
print("=" * 60)
tests = [
test_chart,
test_qrcode,
test_text_image,
test_system_status
]
results = []
for test in tests:
result = test()
results.append(result)
print()
print("=" * 60)
print("测试结果:")
print("=" * 60)
for i, (test, result) in enumerate(zip(tests, results), 1):
status = "✅ 通过" if result else "❌ 失败"
print(f"{i}. {test.__name__}: {status}")
passed = sum(results)
total = len(results)
print(f"\n总计: {passed}/{total} 个测试通过")
if passed == total:
print("🎉 所有测试通过!技能可以正常使用。")
return 0
else:
print("⚠️ 部分测试失败,请检查问题。")
return 1
if __name__ == '__main__':
sys.exit(main())