test_startup.py
4.42 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
AIfeng/2025-07-02 14:01:37
启动测试脚本
用于验证同步版本的启动流程
"""
import os
import sys
import time
# 添加项目根目录到路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def test_directory_creation():
"""
测试目录创建
"""
print("测试目录创建...")
required_dirs = ['logs', 'cache', 'temp', 'audio']
for directory in required_dirs:
if os.path.exists(directory):
print(f"✓ 目录存在: {directory}")
else:
print(f"✗ 目录不存在: {directory}")
try:
os.makedirs(directory, exist_ok=True)
print(f"✓ 已创建目录: {directory}")
except Exception as e:
print(f"✗ 创建目录失败 {directory}: {e}")
return False
return True
def test_utils_import():
"""
测试utils模块导入
"""
print("\n测试utils模块导入...")
try:
from utils import util
print("✓ utils.util 导入成功")
from utils.config_util import get_server_config, get_config
print("✓ utils.config_util 导入成功")
return True
except Exception as e:
print(f"✗ utils模块导入失败: {e}")
return False
def test_core_modules_import():
"""
测试核心模块导入
"""
print("\n测试核心模块导入...")
try:
from recorder_sync import RecorderSync
print("✓ RecorderSync 导入成功")
from funasr_asr_sync import FunASRSync
print("✓ FunASRSync 导入成功")
from server_recording_api_sync import app
print("✓ Flask应用 导入成功")
return True
except Exception as e:
print(f"✗ 核心模块导入失败: {e}")
return False
def test_config_loading():
"""
测试配置加载
"""
print("\n测试配置加载...")
try:
from utils.config_util import load_config, get_server_config
config = load_config()
print("✓ 配置文件加载成功")
server_config = get_server_config()
print(f"✓ 服务器配置: {server_config}")
return True
except Exception as e:
print(f"✗ 配置加载失败: {e}")
return False
def test_log_file_creation():
"""
测试日志文件创建
"""
print("\n测试日志文件创建...")
try:
from utils import util
# 测试日志记录
util.log(1, "测试日志消息", "TestUser")
# 检查日志文件是否存在
log_file = 'logs/system.log'
if os.path.exists(log_file):
print(f"✓ 日志文件创建成功: {log_file}")
# 检查文件大小
file_size = os.path.getsize(log_file)
print(f"✓ 日志文件大小: {file_size} 字节")
return True
else:
print(f"✗ 日志文件不存在: {log_file}")
return False
except Exception as e:
print(f"✗ 日志文件创建失败: {e}")
return False
def main():
"""
主测试函数
"""
print("eman_one 同步版本启动测试")
print("=" * 40)
tests = [
("目录创建", test_directory_creation),
("utils模块导入", test_utils_import),
("核心模块导入", test_core_modules_import),
("配置加载", test_config_loading),
("日志文件创建", test_log_file_creation)
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\n[{passed + 1}/{total}] {test_name}")
print("-" * 30)
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" + "=" * 40)
print(f"测试结果: {passed}/{total} 通过")
if passed == total:
print("✓ 所有测试通过,可以启动main_sync.py")
return True
else:
print("✗ 部分测试失败,请检查问题")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)