完善流量控制 GUI 的开环扫点与手动操作流程
新增可配置开环扫点、多 CSV 前馈表拟合及结果文件生成;补充闭环停止、手动开度安全互锁和 PID 未启用状态显示,并同步更新自动化测试、使用文档、打包配置与 Windows 可执行程序。
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import gui_main
|
||||
|
||||
|
||||
class DummyVar:
|
||||
def __init__(self, value=""):
|
||||
self.value = value
|
||||
|
||||
def get(self):
|
||||
return self.value
|
||||
|
||||
def set(self, value):
|
||||
self.value = value
|
||||
|
||||
|
||||
class DummyWidget:
|
||||
def __init__(self):
|
||||
self.options = {}
|
||||
|
||||
def configure(self, **options):
|
||||
self.options.update(options)
|
||||
|
||||
|
||||
class WorkerSpy:
|
||||
def __init__(self):
|
||||
self.stop_control_count = 0
|
||||
self.stop_open_loop_count = 0
|
||||
self.manual_openings = []
|
||||
self.targets = []
|
||||
|
||||
def request_target(self, target):
|
||||
self.targets.append(target)
|
||||
|
||||
def request_stop_control(self):
|
||||
self.stop_control_count += 1
|
||||
|
||||
def request_open_loop_stop(self):
|
||||
self.stop_open_loop_count += 1
|
||||
|
||||
def request_manual_opening(self, opening):
|
||||
self.manual_openings.append(opening)
|
||||
|
||||
|
||||
def _fake_app(state):
|
||||
return SimpleNamespace(
|
||||
current_state=state,
|
||||
root=object(),
|
||||
worker=WorkerSpy(),
|
||||
detail_var=DummyVar(),
|
||||
target_var=DummyVar("50"),
|
||||
manual_opening_var=DummyVar("25"),
|
||||
target_button=DummyWidget(),
|
||||
stop_control_button=DummyWidget(),
|
||||
open_loop_button=DummyWidget(),
|
||||
_append_log=lambda _message: None,
|
||||
)
|
||||
|
||||
|
||||
def test_open_loop_button_stops_immediately_without_confirmation(monkeypatch):
|
||||
app = _fake_app("OPEN_LOOP")
|
||||
confirmations = []
|
||||
monkeypatch.setattr(
|
||||
gui_main.messagebox,
|
||||
"askyesno",
|
||||
lambda *args, **kwargs: confirmations.append((args, kwargs)),
|
||||
)
|
||||
|
||||
gui_main.FlowControlApp._open_open_loop_dialog(app)
|
||||
|
||||
assert app.worker.stop_open_loop_count == 1
|
||||
assert confirmations == []
|
||||
|
||||
|
||||
def test_separate_stop_control_button_stops_closed_loop():
|
||||
app = _fake_app("CONTROLLING")
|
||||
|
||||
gui_main.FlowControlApp._stop_control(app)
|
||||
|
||||
assert app.worker.stop_control_count == 1
|
||||
assert app.stop_control_button.options["state"] == "disabled"
|
||||
|
||||
|
||||
def test_target_can_be_changed_while_closed_loop_is_running():
|
||||
app = _fake_app("CONTROLLING")
|
||||
app.target_var.set("72.5")
|
||||
|
||||
gui_main.FlowControlApp._set_target(app)
|
||||
|
||||
assert app.worker.targets == [72.5]
|
||||
assert app.detail_var.get() == "正在设置目标流量 72.5 SLM…"
|
||||
|
||||
|
||||
def test_controlling_state_keeps_target_controls_and_stop_button_enabled():
|
||||
app = object.__new__(gui_main.FlowControlApp)
|
||||
app.status_var = DummyVar()
|
||||
app.detail_var = DummyVar()
|
||||
app.active_target_var = DummyVar()
|
||||
app.fit_in_progress = False
|
||||
app.closing = False
|
||||
for name in (
|
||||
"status_badge",
|
||||
"host_entry",
|
||||
"port_entry",
|
||||
"slave_entry",
|
||||
"model_browse_button",
|
||||
"model_builtin_button",
|
||||
"open_loop_button",
|
||||
"connect_button",
|
||||
"disconnect_button",
|
||||
"target_entry",
|
||||
"target_button",
|
||||
"stop_control_button",
|
||||
"manual_opening_entry",
|
||||
"manual_opening_button",
|
||||
"fit_model_button",
|
||||
):
|
||||
setattr(app, name, DummyWidget())
|
||||
|
||||
gui_main.FlowControlApp._apply_state(app, "CONTROLLING", "闭环运行中")
|
||||
|
||||
assert app.target_entry.options["state"] == "normal"
|
||||
assert app.target_button.options["state"] == "normal"
|
||||
assert "text" not in app.target_button.options
|
||||
assert app.stop_control_button.options["state"] == "normal"
|
||||
|
||||
|
||||
def test_manual_opening_during_control_only_shows_warning(monkeypatch):
|
||||
app = _fake_app("CONTROLLING")
|
||||
warnings = []
|
||||
monkeypatch.setattr(
|
||||
gui_main.messagebox,
|
||||
"showwarning",
|
||||
lambda *args, **kwargs: warnings.append((args, kwargs)),
|
||||
)
|
||||
|
||||
gui_main.FlowControlApp._set_manual_opening(app)
|
||||
|
||||
assert len(warnings) == 1
|
||||
assert "停止流量控制" in warnings[0][0][0]
|
||||
assert app.worker.stop_control_count == 0
|
||||
assert app.worker.manual_openings == []
|
||||
Reference in New Issue
Block a user