-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
221 lines (184 loc) · 5.43 KB
/
test.py
File metadata and controls
221 lines (184 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env python3
"""
测试脚本 - 验证所有模块是否正常工作
"""
import sys
import os
def test_imports():
"""测试模块导入"""
print("🧪 测试模块导入...\n")
try:
print(" [1/5] 导入 feishu.py...")
from mcp_tools.feishu import FeishuAPI
print(" ✅ feishu.py 导入成功\n")
except Exception as e:
print(f" ❌ feishu.py 导入失败: {e}\n")
return False
try:
print(" [2/5] 导入 image_match.py...")
from modules.image_match import ImageMatcher
print(" ✅ image_match.py 导入成功\n")
except Exception as e:
print(f" ❌ image_match.py 导入失败: {e}\n")
return False
try:
print(" [3/5] 导入 layout_engine.py...")
from modules.layout_engine import WeChatLayoutEngine
print(" ✅ layout_engine.py 导入成功\n")
except Exception as e:
print(f" ❌ layout_engine.py 导入失败: {e}\n")
return False
try:
print(" [4/5] 导入 content_gen.py...")
from modules.content_gen import ContentGenerator
print(" ✅ content_gen.py 导入成功\n")
except Exception as e:
print(f" ❌ content_gen.py 导入失败: {e}\n")
return False
try:
print(" [5/5] 导入 main.py...")
from main import WeChatBurstGen
print(" ✅ main.py 导入成功\n")
except Exception as e:
print(f" ❌ main.py 导入失败: {e}\n")
return False
return True
def test_dependencies():
"""测试依赖包"""
print("🧪 测试依赖包...\n")
dependencies = [
'anthropic',
'requests',
'jinja2',
'markdown'
]
all_ok = True
for dep in dependencies:
try:
__import__(dep)
print(f" ✅ {dep}")
except ImportError:
print(f" ❌ {dep} - 未安装")
all_ok = False
print()
return all_ok
def test_env_vars():
"""测试环境变量"""
print("🧪 测试环境变量...\n")
required_vars = [
'FEISHU_APP_ID',
'FEISHU_APP_SECRET'
]
optional_vars = [
'FEISHU_BITABLE_TOKEN',
'FEISHU_TABLE_ID',
'FEISHU_FOLDER_TOKEN',
'ANTHROPIC_API_KEY'
]
print(" 必需变量:")
all_ok = True
for var in required_vars:
value = os.getenv(var)
if value:
masked = value[:10] + "..." if len(value) > 10 else value
print(f" ✅ {var} = {masked}")
else:
print(f" ⚠️ {var} - 未设置(使用 --no-feishu 可跳过)")
all_ok = False
print("\n 可选变量:")
for var in optional_vars:
value = os.getenv(var)
if value:
masked = value[:10] + "..." if len(value) > 10 else value
print(f" ✅ {var} = {masked}")
else:
print(f" ℹ️ {var} - 未设置")
print()
return all_ok
def test_directories():
"""测试目录结构"""
print("🧪 测试目录结构...\n")
dirs = [
'config',
'modules',
'mcp_tools',
'templates',
'output'
]
all_ok = True
for d in dirs:
if os.path.isdir(d):
print(f" ✅ {d}/")
else:
print(f" ❌ {d}/ - 不存在")
all_ok = False
print()
return all_ok
def test_files():
"""测试关键文件"""
print("🧪 测试关键文件...\n")
files = [
'skill.json',
'main.py',
'README.md',
'config/FEISHU_SETUP.md',
'mcp_tools/feishu.py',
'modules/image_match.py',
'modules/layout_engine.py',
'modules/content_gen.py'
]
all_ok = True
for f in files:
if os.path.isfile(f):
print(f" ✅ {f}")
else:
print(f" ❌ {f} - 不存在")
all_ok = False
print()
return all_ok
def main():
print("=" * 70)
print("🧪 公众号爆款生成器 - 测试脚本")
print("=" * 70)
print()
# 切换到脚本目录
os.chdir(os.path.dirname(os.path.abspath(__file__)))
results = []
# 运行测试
results.append(("目录结构", test_directories()))
results.append(("关键文件", test_files()))
results.append(("依赖包", test_dependencies()))
results.append(("模块导入", test_imports()))
results.append(("环境变量", test_env_vars()))
# 汇总结果
print("=" * 70)
print("📊 测试结果汇总")
print("=" * 70)
print()
passed = 0
total = len(results)
for name, ok in results:
status = "✅ 通过" if ok else "❌ 失败"
print(f" {name:12s} {status}")
if ok:
passed += 1
print()
print("=" * 70)
if passed == total:
print("🎉 所有测试通过!系统已就绪。")
print()
print("快速开始:")
print(' python main.py "如何提升工作效率" -c 职场 --no-feishu')
print()
else:
print(f"⚠️ {total - passed}/{total} 项测试失败")
print()
print("建议:")
print(" 1. 安装缺失的依赖: pip install anthropic requests jinja2 markdown")
print(" 2. 配置飞书环境变量: 参考 config/FEISHU_SETUP.md")
print(" 3. 或使用 --no-feishu 模式仅生成本地文件")
print()
print("=" * 70)
print()
if __name__ == "__main__":
main()