-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_debug.py
More file actions
132 lines (97 loc) · 3.31 KB
/
test_debug.py
File metadata and controls
132 lines (97 loc) · 3.31 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
调试测试脚本
用于测试各个模块的功能
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from core.serial_manager import SerialManager
from core.command_builder import build_command, validate_parameters
import config
def test_command_builder():
"""测试命令构建器"""
print("=== 测试命令构建器 ===")
# 测试正常参数
cmd = build_command(50, 15, 180)
print(f"正常命令: {repr(cmd)}")
# 测试边界参数
cmd = build_command(0, -30, 0)
print(f"边界命令: {repr(cmd)}")
# 测试超出范围参数
cmd = build_command(150, -50, 400)
print(f"超范围命令: {repr(cmd)}")
# 测试参数验证
result = validate_parameters(50, 15, 180)
print(f"参数验证 (有效): {result}")
result = validate_parameters(150, -50, 400)
print(f"参数验证 (无效): {result}")
print()
def test_serial_manager():
"""测试串口管理器"""
print("=== 测试串口管理器 ===")
serial_mgr = SerialManager()
# 测试获取串口列表
ports = serial_mgr.list_ports()
print(f"可用串口: {ports}")
if not ports:
print("❌ 没有可用的串口")
return
# 测试连接到第一个串口
test_port = ports[0]
print(f"尝试连接到: {test_port}")
success = serial_mgr.connect(test_port, config.BAUDRATE)
if success:
print(f"✅ 成功连接到 {test_port}")
# 测试发送命令
test_cmd = build_command(25, 10, 90)
print(f"发送测试命令: {repr(test_cmd)}")
serial_mgr.send(test_cmd)
# 等待一段时间查看响应
import time
time.sleep(2)
# 断开连接
serial_mgr.disconnect()
print("✅ 已断开连接")
else:
print(f"❌ 连接失败: {test_port}")
print()
def test_config():
"""测试配置"""
print("=== 测试配置 ===")
print(f"波特率: {config.BAUDRATE}")
print(f"日志目录: {config.LOG_DIR}")
print(f"命令终止符: {repr(config.COMMAND_TERMINATOR)}")
print(f"窗口标题: {config.WINDOW_TITLE}")
print()
def main():
"""主测试函数"""
print("🔧 开始调试测试...")
print("=" * 50)
test_config()
test_command_builder()
test_serial_manager()
print("=" * 50)
print("🎉 测试完成!")
# 测试GUI(可选)
test_gui = input("是否测试GUI?(y/n): ").strip().lower()
if test_gui == 'y':
try:
from PyQt5.QtWidgets import QApplication
from GUI.main_window import MainWindow
app = QApplication([])
window = MainWindow()
window.show()
print("✅ GUI已启动,请在窗口中测试功能")
print(" - 检查串口列表是否正确")
print(" - 测试连接/断开功能")
print(" - 测试滑块控制")
print(" - 测试命令发送")
app.exec_()
except Exception as e:
print(f"❌ GUI测试失败: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
main()