test: simulate all UI buttons and handle log folder errors
This commit is contained in:
1 parent
42e8719026
commit
b86e4e315a
5 files changed
+1796
-1
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,76 @@
|
||||
# 2026-11-11:逐按钮模拟操作验证
|
||||
|
||||
基线:42e87190263453c8e3a7001d5768741b3b3a2c38。
|
||||
|
||||
全量 Python 测试 **1,835 passed**,只有既有的 STA COM 模式警告;Windows 私有桌面的界面组 **276 passed** 并正常退出。记录了 **281 次点击信号**、**78 种控件标识**和 **28 张代表性截图**。新增测试包含真实 Qt 文件选择和确认按钮、连点、停止、取消、窗口关闭和动态结果入口。
|
||||
|
||||
## 逐按钮模拟操作结果
|
||||
|
||||
Windows 原生 Qt 控件,独立私有桌面。48 个应用按钮/复选项全部触发点击信号,另验证 3 个菜单页签;276 项界面相关测试通过。
|
||||
|
||||
文件选择和确认框使用真实 Qt 对话框及其按钮;原生读写、恢复、保存、取消、强制结束均使用隔离替身。通过表示界面连接、参数、状态及错误处理通过,不表示真实 Mentor 操作通过。
|
||||
|
||||
| 控件 | 按钮 | 结果 | 验证点 |
|
||||
| --- | --- | --- | --- |
|
||||
| BackupRecoveryDialog.browse_button | 选择… | 通过 | 真实备份工程选择框打开/取消 |
|
||||
| BackupRecoveryDialog.restore_button | 恢复并校验 | 通过 | 无效来源拒绝;确认/拒绝;显示受控恢复结果 |
|
||||
| BackupRecoveryDialog.close_button | 关闭 | 通过 | 空闲关闭恢复窗口 |
|
||||
| BackupRecoveryDialog.cancel_queue_button | 取消排队 | 通过 | 取消等待票据,不调用恢复后端 |
|
||||
| MainWindow.native_lm_verify_check | 使用 Library Manager 原生 Verify(Win10 兼容测试) | 通过 | 勾选状态切换,原生 Verify 选项保持独立 |
|
||||
| MainWindow.advanced_toggle | 高级设置 | 通过 | 展开和收起高级设置 |
|
||||
| MainWindow.select_visible_button | 选择可见项 | 通过 | 只勾选可见条目 |
|
||||
| MainWindow.clear_selection_button | 清空选择 | 通过 | 清空勾选 |
|
||||
| MainWindow.load_button | 读取 CBB | 通过 | 读取当前库并更新清单 |
|
||||
| MainWindow.browse_button | 选择 | 通过 | 真实选择框打开/取消;取消不触发读取 |
|
||||
| MainWindow.selected_batch_button | 批量校验已选 | 通过 | 真实确认/拒绝;仅执行可见非 READY 已选项 |
|
||||
| MainWindow.batch_button | 校验可见非 READY | 通过 | 真实确认/拒绝;只执行可见非 READY 项 |
|
||||
| MainWindow.icdb_repair_button | ICDB 批量检查 | 通过 | 开始独立 ICDB 检查,不启用自动 Repair |
|
||||
| MainWindow.backup_restore_button | 从备份恢复 CBB… | 通过 | 为当前非 READY 目标打开备份恢复窗口 |
|
||||
| MainWindow.reimport_button | 选择工程副本恢复失败项… | 通过 | 副本恢复仍绑定失败 CBB |
|
||||
| MainWindow.stop_button | 当前项完成后停止 | 通过 | 设置停止标志,后续目标不再执行 |
|
||||
| MainWindow.logs_button | 打开日志目录 | 通过 | 打开正确目录;目录及系统打开失败时显示错误 |
|
||||
| MainWindow.recovery_button | 打开异常证据 | 通过 | 打开正确证据路径;系统打开失败时显示错误 |
|
||||
| MainWindow.native_backup_button | 版本历史与备份… | 通过 | 只启动一次;收到关闭回执后恢复可用 |
|
||||
| MainWindow.icdb_stop_button | 停止检查 | 通过 | 停止当前后台检查,不再打开后续项 |
|
||||
| MainWindow.add_button | 新增 CBB… | 通过 | 打开新增操作窗口 |
|
||||
| MainWindow.update_button | 用工程替换已选 CBB… | 通过 | 打开所选目标的更新窗口 |
|
||||
| MainWindow.remove_button | 移除已选… | 通过 | 打开所选目标的移除窗口 |
|
||||
| MainWindow.release_library_button | 释放残留会话… | 通过 | 打开当前库的释放预览 |
|
||||
| MainWindow.queue_release_button | 查看残留会话… | 通过 | 打开等待库的释放预览,关闭面板不误解锁任务 |
|
||||
| MainWindow.runtime_log_toggle | 查看运行日志 | 通过 | 显示/隐藏运行输出 |
|
||||
| ManagementDialog.sources_button | 选择来源工程… | 通过 | 真实工程选择框打开/取消并更新来源行 |
|
||||
| ManagementDialog.auto_verify | 本批次上传后自动校验 | 通过 | 切换本批次自动校验选项 |
|
||||
| ManagementDialog.release_wait_button | 查看残留会话… | 通过 | 传出等待释放的目标库 |
|
||||
| ManagementDialog.logs_button | 查看日志 | 通过 | 显示/隐藏管理日志 |
|
||||
| ManagementDialog.execute_button | 预览并确认执行… | 通过 | 真实确认/拒绝,重复点击不重复执行 |
|
||||
| ManagementDialog.stop_button | 当前项结束后停止 | 通过 | 设置管理任务停止标志 |
|
||||
| ManagementDialog.close_button | 关闭 | 通过 | 空闲关闭,执行中禁用点击不打断任务 |
|
||||
| PcbRestoreDialog.manual_button | 最后手动保存 | 通过 | 只选择最后手动保存版本,关闭不覆盖已有选择 |
|
||||
| PcbRestoreDialog.auto_button | 自动保存 | 通过 | 只选择自动保存版本,关闭不覆盖已有选择 |
|
||||
| PcbRestoreDialog.cancel_button | 取消 | 通过 | 取消选择,不默认回退版本 |
|
||||
| ResidualReleaseDialog.refresh_button | 重新检查 | 通过 | 重新扫描预览,不执行释放 |
|
||||
| ResidualReleaseDialog.confirm_button | 确认释放 | 通过 | 传递当前确认范围,显示实际释放结果 |
|
||||
| ResidualReleaseDialog.prompt_button | 处理保存提示… | 通过 | 真实是/否/取消,传递对应保存选择 |
|
||||
| ResidualReleaseDialog.details_button | 查看原生提示… | 通过 | 显示原生提示全文和详细信息 |
|
||||
| ResidualReleaseDialog.cancel_native_button | 请求原生取消… | 通过 | 真实确认/拒绝后发送受控取消请求 |
|
||||
| ResidualReleaseDialog.force_button | 强制结束客户端… | 通过 | 真实确认/取消后传递强制标志;未调用实际强杀 |
|
||||
| ResidualReleaseDialog.close_button | 关闭 | 通过 | 空闲关闭;执行中请求停止并等待当前项返回 |
|
||||
| Result.batch_release | 查看残留并释放… | 通过 | 从批量失败结果打开当前库释放入口 |
|
||||
| Result.batch_resume | 继续未执行项 | 通过 | 释放确认后只执行此前未执行的目标 |
|
||||
| Result.batch_copy | 选择副本恢复… | 通过 | 兼容维护结果中的副本恢复仍绑定失败工程 |
|
||||
| Result.icdb_release | 查看残留并释放… | 通过 | 从 ICDB 结果打开对应库释放入口 |
|
||||
| Result.icdb_copy | 选择副本恢复… | 通过 | 从 ICDB 结果打开对应失败工程的副本恢复 |
|
||||
|
||||
每项对应的测试编号、点击次数、完整事件记录及代表性截图见同目录 button-matrix.json / windows-all.json。
|
||||
|
||||
本轮额外修复:打开日志目录时,目录创建失败或系统拒绝打开不再向 Qt 事件循环抛出未处理异常,改用现有错误提示。
|
||||
|
||||
未验证:真实 Mentor 写库、ICDB 修复、Windows 10、跨机器共享库。
|
||||
|
||||
## 验证边界与构建记录
|
||||
|
||||
实际原生写库、历史回退、保存、原生取消及强制结束均使用隔离替身。未触碰现场工程或中心库,未证明 ICDB 原生修复成功;Windows 10 和跨机器共享库仍未验收。
|
||||
|
||||
首次候选构建因 C 盘空间不足在收集文件阶段失败,未计为通过。本轮未完成构建已迁至 F 盘继续,原候选和测试证据保留。最终构建及冻结验证结果见相邻验证 JSON。
|
||||
|
||||
逐按钮的测试编号与点击次数、界面 XML、截图路径和文件哈希保存在相邻验证 JSON 及其引用的本机证据中。截图只提供代表性界面,逐项结论以测试断言和点击记录为依据。
|
||||
@@ -1688,7 +1688,11 @@ class MainWindow(QWidget):
|
||||
self.busy = False; self._update()
|
||||
|
||||
def open_logs(self):
|
||||
self.data_root.mkdir(parents=True, exist_ok=True); os.startfile(str(self.data_root))
|
||||
try:
|
||||
self.data_root.mkdir(parents=True, exist_ok=True)
|
||||
os.startfile(str(self.data_root))
|
||||
except Exception as error:
|
||||
self._display_error(error)
|
||||
|
||||
def recover(self):
|
||||
if not self.recovery_path: return
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
"""Real Qt click helpers; external native writers stay outside these UI tests."""
|
||||
from contextlib import contextmanager
|
||||
|
||||
from PySide6.QtCore import QPoint, QTimer, Qt
|
||||
from PySide6.QtWidgets import QApplication, QCheckBox, QDialogButtonBox, QFileDialog, QMessageBox
|
||||
|
||||
|
||||
def press(qtbot, button):
|
||||
assert button.isVisible(), button.text()
|
||||
assert button.isEnabled(), button.text()
|
||||
if isinstance(button, QCheckBox):
|
||||
qtbot.mouseClick(button, Qt.LeftButton, pos=QPoint(8, button.height()//2))
|
||||
else:
|
||||
qtbot.mouseClick(button, Qt.LeftButton)
|
||||
|
||||
|
||||
def tab(qtbot, window, index):
|
||||
qtbot.mouseClick(window.section_tabs, Qt.LeftButton,
|
||||
pos=window.section_tabs.tabRect(index).center())
|
||||
assert window.section_stack.currentIndex() == index
|
||||
|
||||
|
||||
@contextmanager
|
||||
def modal_click(qtbot, standard=None, *, file=None, cancel_file=False):
|
||||
"""Answer the real nested dialog by clicking its actual button."""
|
||||
timer = QTimer()
|
||||
deadline = QTimer()
|
||||
deadline.setSingleShot(True)
|
||||
seen, errors = [], []
|
||||
prepared = False
|
||||
|
||||
def answer():
|
||||
nonlocal prepared
|
||||
dialog = QApplication.activeModalWidget()
|
||||
try:
|
||||
if standard is not None and isinstance(dialog, QMessageBox):
|
||||
button = dialog.button(standard)
|
||||
if button is None:
|
||||
return
|
||||
elif isinstance(dialog, QFileDialog) and (file is not None or cancel_file):
|
||||
box = dialog.findChild(QDialogButtonBox)
|
||||
if not cancel_file and not prepared:
|
||||
dialog.setDirectory(str(file.parent))
|
||||
dialog.selectFile(str(file))
|
||||
prepared = True
|
||||
return
|
||||
button = box.button(QDialogButtonBox.Cancel if cancel_file else QDialogButtonBox.Open)
|
||||
else:
|
||||
return
|
||||
if button is None or not button.isEnabled():
|
||||
return
|
||||
seen.append(dialog.windowTitle())
|
||||
timer.stop()
|
||||
press(qtbot, button)
|
||||
except Exception as error:
|
||||
errors.append(str(error))
|
||||
timer.stop()
|
||||
if dialog is not None:
|
||||
dialog.reject()
|
||||
|
||||
def timeout():
|
||||
errors.append('The expected modal button did not become available')
|
||||
dialog = QApplication.activeModalWidget()
|
||||
if dialog is not None:
|
||||
dialog.reject()
|
||||
|
||||
timer.timeout.connect(answer)
|
||||
deadline.timeout.connect(timeout)
|
||||
timer.start(10)
|
||||
deadline.start(4000)
|
||||
try:
|
||||
yield seen
|
||||
finally:
|
||||
timer.stop()
|
||||
deadline.stop()
|
||||
assert not errors, errors
|
||||
assert len(seen) == 1, seen
|
||||
@@ -0,0 +1,573 @@
|
||||
"""Click every owned control; use real dialogs and controlled native outcomes."""
|
||||
from pathlib import Path
|
||||
from threading import Event
|
||||
from types import SimpleNamespace
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QMessageBox, QPushButton, QTextEdit
|
||||
from shiboken6 import isValid
|
||||
|
||||
from button_simulation import modal_click, press, tab
|
||||
from cbb_refresh_verify.management import Capability, ManagementRequest, ManagementResult
|
||||
from cbb_refresh_verify.models import CbbRecord, LibraryReadResult
|
||||
from cbb_refresh_verify.verify_runner import VerifyRequest, VerifyResult
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def controls(qtbot, tmp_path, monkeypatch, qapp):
|
||||
import cbb_refresh_verify.ui.main_window as ui
|
||||
from cbb_refresh_verify import library_lock
|
||||
old_native = qapp.testAttribute(Qt.AA_DontUseNativeDialogs)
|
||||
qapp.setAttribute(Qt.AA_DontUseNativeDialogs, True)
|
||||
library = tmp_path/'library.lmc'
|
||||
library.touch()
|
||||
source = tmp_path/'Beta.prj'
|
||||
source.write_text('KEY iCDBDir "database"\n', encoding='utf-8')
|
||||
state = SimpleNamespace(library=library, source=source, reads=[], runs=[], opened=[],
|
||||
entered=Event(), finish=Event(), native=[], result=None)
|
||||
state.finish.set()
|
||||
records = (CbbRecord('Ready', 'Power', status='READY'),
|
||||
CbbRecord('Beta', 'Power', status='PENDING'), CbbRecord('Gamma', 'Analog', status='UNKNOWN'))
|
||||
lease = SimpleNamespace(mentor_path=library, display_path=library, drive='', remote_root='',
|
||||
close=lambda: None, retain_for_recovery=lambda: None)
|
||||
|
||||
def verify(request):
|
||||
state.runs.append(request)
|
||||
state.entered.set()
|
||||
assert state.finish.wait(5)
|
||||
return state.result or VerifyResult('CHECKED' if request.maintenance else 'PASS')
|
||||
|
||||
monkeypatch.setattr(ui, 'preflight_skip_reason', lambda *_: None)
|
||||
monkeypatch.setattr(ui.os, 'startfile', lambda path: state.opened.append(Path(path)))
|
||||
monkeypatch.setattr(library_lock, 'inspect_residual_sessions',
|
||||
lambda path: dict(library=str(path), sessions=[]))
|
||||
adapter = SimpleNamespace(capabilities=lambda: {op: Capability(True, 'validated fixture')
|
||||
for op in ('add', 'update', 'remove')})
|
||||
window = ui.MainWindow(reader=lambda path: (state.reads.append(path) or LibraryReadResult(records)),
|
||||
verifier=verify, data_root=tmp_path/'data', path_lease_factory=lambda _: lease,
|
||||
status_refresher=lambda names, _: {name:'PENDING' for name in names}, management_adapter=adapter)
|
||||
state.window = window
|
||||
window.show()
|
||||
window.lmc_edit.setText(str(library))
|
||||
press(qtbot, window.load_button)
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
yield state
|
||||
state.finish.set()
|
||||
window.stop.set()
|
||||
if window._icdb_active():
|
||||
window.icdb_task.cancel()
|
||||
window.native_queue.wake()
|
||||
if window._closing:
|
||||
qtbot.waitUntil(lambda: not isValid(window) or not window.isVisible())
|
||||
if isValid(window):
|
||||
window.deleteLater()
|
||||
qtbot.waitUntil(lambda: not isValid(window))
|
||||
qapp.setAttribute(Qt.AA_DontUseNativeDialogs, old_native)
|
||||
return
|
||||
dialog = getattr(window, 'management_dialog', None)
|
||||
if dialog is not None and isValid(dialog):
|
||||
dialog.stop.set()
|
||||
qtbot.waitUntil(lambda: not window.busy or (dialog is not None and not dialog.busy))
|
||||
for child in window.findChildren(QMessageBox):
|
||||
if isValid(child):
|
||||
child.close()
|
||||
for name in ('management_dialog', 'backup_dialog', 'release_dialog'):
|
||||
child = getattr(window, name, None)
|
||||
if child is not None and isValid(child):
|
||||
qtbot.waitUntil(lambda child=child: not child.busy)
|
||||
child.close()
|
||||
qtbot.waitUntil(lambda: not window.busy and not window._icdb_active())
|
||||
window.close()
|
||||
qtbot.waitUntil(lambda: not isValid(window) or not window.isVisible())
|
||||
if isValid(window):
|
||||
window.deleteLater()
|
||||
qtbot.waitUntil(lambda: not isValid(window))
|
||||
qapp.setAttribute(Qt.AA_DontUseNativeDialogs, old_native)
|
||||
|
||||
|
||||
def test_main_navigation_selection_and_toggles(controls, qtbot):
|
||||
w = controls.window
|
||||
for index in (2, 1, 0, 2, 0):
|
||||
tab(qtbot, w, index)
|
||||
press(qtbot, w.select_visible_button)
|
||||
assert len(w.selected_records()) == 3
|
||||
press(qtbot, w.clear_selection_button)
|
||||
assert w.selected_records() == ()
|
||||
press(qtbot, w.advanced_toggle)
|
||||
assert w.advanced_panel.isVisible()
|
||||
original = w.native_lm_verify_check.isChecked()
|
||||
press(qtbot, w.native_lm_verify_check)
|
||||
assert w.native_lm_verify_check.isChecked() != original
|
||||
press(qtbot, w.native_lm_verify_check)
|
||||
press(qtbot, w.advanced_toggle)
|
||||
assert not w.advanced_panel.isVisible()
|
||||
press(qtbot, w.runtime_log_toggle)
|
||||
assert w.output.isVisible()
|
||||
press(qtbot, w.runtime_log_toggle)
|
||||
assert not w.output.isVisible()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cancel', [True, False])
|
||||
def test_main_library_chooser_real_open_and_cancel(controls, qtbot, cancel):
|
||||
w = controls.window
|
||||
before = len(controls.reads)
|
||||
with modal_click(qtbot, file=None if cancel else controls.library, cancel_file=cancel):
|
||||
press(qtbot, w.browse_button)
|
||||
qtbot.waitUntil(lambda: not w.busy)
|
||||
assert len(controls.reads) == before + (0 if cancel else 1)
|
||||
press(qtbot, w.load_button)
|
||||
qtbot.waitUntil(lambda: not w.busy)
|
||||
assert len(controls.reads) == before + (1 if cancel else 2)
|
||||
|
||||
|
||||
def test_main_logs_and_evidence_buttons_open_the_correct_paths(controls, qtbot):
|
||||
w = controls.window
|
||||
press(qtbot, w.logs_button)
|
||||
evidence = controls.library.parent/'evidence'
|
||||
evidence.mkdir()
|
||||
w.recovery_path = evidence
|
||||
w.recovery_button.setEnabled(True)
|
||||
press(qtbot, w.recovery_button)
|
||||
assert controls.opened == [w.data_root, evidence]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('attribute', ['selected_batch_button', 'batch_button', 'icdb_repair_button'])
|
||||
@pytest.mark.parametrize('answer', [QMessageBox.No, QMessageBox.Yes])
|
||||
def test_main_check_buttons_have_real_confirm_and_cancel_paths(controls, qtbot, attribute, answer):
|
||||
w = controls.window
|
||||
if attribute == 'icdb_repair_button':
|
||||
tab(qtbot, w, 1)
|
||||
w.search_edit.setText('Beta')
|
||||
press(qtbot, w.select_visible_button)
|
||||
with modal_click(qtbot, answer):
|
||||
press(qtbot, getattr(w, attribute))
|
||||
qtbot.waitUntil(lambda: not w.busy and not w._icdb_active())
|
||||
assert [request.block_name for request in controls.runs] == ([] if answer == QMessageBox.No else ['Beta'])
|
||||
if controls.runs:
|
||||
assert controls.runs[0].auto_repair is False
|
||||
summary = w.summary
|
||||
details = next((b for b in summary.findChildren(QPushButton) if 'Details' in b.text()), None)
|
||||
assert details is not None
|
||||
press(qtbot, details)
|
||||
assert summary.findChild(QTextEdit).isVisible()
|
||||
press(qtbot, summary.button(QMessageBox.Ok))
|
||||
assert not isValid(summary) or not summary.isVisible()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('background', [True, False])
|
||||
def test_main_stop_buttons_stop_additional_items(controls, qtbot, background):
|
||||
w = controls.window
|
||||
controls.finish.clear()
|
||||
if background:
|
||||
tab(qtbot, w, 1)
|
||||
button = w.icdb_repair_button if background else w.batch_button
|
||||
try:
|
||||
with modal_click(qtbot, QMessageBox.Yes):
|
||||
press(qtbot, button)
|
||||
qtbot.waitUntil(controls.entered.is_set)
|
||||
stop = w.icdb_stop_button if background else w.stop_button
|
||||
press(qtbot, stop)
|
||||
assert (w.icdb_task.stop if background else w.stop).is_set()
|
||||
finally:
|
||||
controls.finish.set()
|
||||
qtbot.waitUntil(lambda: not w.busy and not w._icdb_active())
|
||||
assert [request.block_name for request in controls.runs] == ['Beta']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('operation', ['add', 'update', 'remove'])
|
||||
def test_main_management_buttons_open_the_requested_operation(controls, qtbot, operation):
|
||||
w = controls.window
|
||||
tab(qtbot, w, 2)
|
||||
w.search_edit.setText('Beta')
|
||||
press(qtbot, w.select_visible_button)
|
||||
press(qtbot, getattr(w, operation+'_button'))
|
||||
dialog = w.management_dialog
|
||||
assert dialog.operation == operation and w.busy
|
||||
if operation != 'add':
|
||||
assert [request.name for request in dialog.requests()] == ['Beta']
|
||||
press(qtbot, dialog.close_button)
|
||||
qtbot.waitUntil(lambda: not w.busy)
|
||||
|
||||
|
||||
def test_main_backup_restore_and_release_entries(controls, qtbot):
|
||||
w = controls.window
|
||||
tab(qtbot, w, 1)
|
||||
w.search_edit.setText('Beta')
|
||||
press(qtbot, w.select_visible_button)
|
||||
press(qtbot, w.backup_restore_button)
|
||||
assert w.backup_dialog.block_combo.currentText() == 'Beta'
|
||||
press(qtbot, w.backup_dialog.close_button)
|
||||
tab(qtbot, w, 2)
|
||||
press(qtbot, w.release_library_button)
|
||||
qtbot.waitUntil(lambda: not w.release_dialog.busy)
|
||||
assert w.release_dialog.plan['library'] == str(controls.library)
|
||||
press(qtbot, w.release_dialog.close_button)
|
||||
qtbot.waitUntil(lambda: not w.busy)
|
||||
|
||||
|
||||
def test_native_backup_entry_starts_once_and_reenables_after_receipt(controls, qtbot):
|
||||
w = controls.window
|
||||
tab(qtbot, w, 1)
|
||||
w.search_edit.setText('Beta')
|
||||
press(qtbot, w.select_visible_button)
|
||||
job = controls.library.parent/'request.json'
|
||||
job.write_text('{}', encoding='utf-8')
|
||||
ended = Event()
|
||||
session = SimpleNamespace(library=controls.library, block='Beta', job=job,
|
||||
process=SimpleNamespace(poll=lambda: 0 if ended.is_set() else None))
|
||||
w.native_backup_launcher = lambda request: (controls.native.append(request) or session)
|
||||
press(qtbot, w.native_backup_button)
|
||||
qtbot.waitUntil(lambda: not w.busy)
|
||||
for _ in range(5):
|
||||
qtbot.mouseClick(w.native_backup_button, Qt.LeftButton)
|
||||
assert len(controls.native) == 1 and not w.native_backup_button.isEnabled()
|
||||
job.with_name('result.json').write_text(json.dumps(dict(status='CLOSED', safe_to_continue=True,
|
||||
library=str(controls.library), block='Beta', restore_confirmed=False)), encoding='utf-8')
|
||||
ended.set()
|
||||
qtbot.waitUntil(lambda: w._native_backup_session is None and not w.busy, timeout=3000)
|
||||
assert w.native_backup_button.isEnabled()
|
||||
assert 'PASS' not in w.cbb_table.item(w._row_by_name['Beta'], 3).text()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('operation', ['add', 'update'])
|
||||
@pytest.mark.parametrize('cancel', [True, False])
|
||||
def test_management_source_chooser_and_auto_verify_toggle(controls, qtbot, operation, cancel):
|
||||
from cbb_refresh_verify.ui.management_dialog import ManagementDialog
|
||||
req = ManagementRequest(operation, controls.library, '' if operation == 'add' else 'Beta')
|
||||
dialog = ManagementDialog([req])
|
||||
qtbot.addWidget(dialog)
|
||||
dialog.show()
|
||||
with modal_click(qtbot, file=None if cancel else controls.source, cancel_file=cancel):
|
||||
press(qtbot, dialog.sources_button)
|
||||
assert dialog.table.rowCount() == (0 if operation == 'add' and cancel else 1)
|
||||
if not cancel:
|
||||
assert dialog.requests()[0].source == controls.source
|
||||
checked = dialog.auto_verify.isChecked()
|
||||
press(qtbot, dialog.auto_verify)
|
||||
assert dialog.auto_verify.isChecked() != checked
|
||||
press(qtbot, dialog.logs_button)
|
||||
assert dialog.output.isVisible()
|
||||
press(qtbot, dialog.logs_button)
|
||||
assert not dialog.output.isVisible()
|
||||
press(qtbot, dialog.close_button)
|
||||
assert not dialog.isVisible()
|
||||
|
||||
|
||||
def test_management_confirm_cancel_execute_stop_and_repeated_click(controls, qtbot):
|
||||
from cbb_refresh_verify.ui.management_dialog import ManagementDialog
|
||||
entered, finish = Event(), Event()
|
||||
calls = []
|
||||
def runner(requests, **kwargs):
|
||||
calls.extend(requests)
|
||||
entered.set()
|
||||
assert finish.wait(5)
|
||||
return [ManagementResult('remove', controls.library, 'Beta', 'Logical-Physical', None,
|
||||
False, 'complete', 'REMOVED', True)]
|
||||
dialog = ManagementDialog([ManagementRequest('remove', controls.library, 'Beta')], runner=runner)
|
||||
qtbot.addWidget(dialog)
|
||||
dialog.show()
|
||||
with modal_click(qtbot, QMessageBox.No):
|
||||
press(qtbot, dialog.execute_button)
|
||||
assert calls == [] and not dialog.executed
|
||||
try:
|
||||
with modal_click(qtbot, QMessageBox.Yes):
|
||||
press(qtbot, dialog.execute_button)
|
||||
qtbot.waitUntil(entered.is_set)
|
||||
for _ in range(5):
|
||||
qtbot.mouseClick(dialog.execute_button, Qt.LeftButton)
|
||||
qtbot.mouseClick(dialog.close_button, Qt.LeftButton)
|
||||
assert len(calls) == 1 and dialog.isVisible()
|
||||
press(qtbot, dialog.stop_button)
|
||||
assert dialog.stop.is_set()
|
||||
finally:
|
||||
finish.set()
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
assert '已移除' in dialog.status_label.text()
|
||||
press(qtbot, dialog.close_button)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('cancel', [True, False])
|
||||
def test_recovery_real_source_chooser_and_confirmation_options(controls, qtbot, cancel):
|
||||
from cbb_refresh_verify.ui.backup_recovery_dialog import BackupRecoveryDialog
|
||||
calls = []
|
||||
def recover(request, source, **kwargs):
|
||||
calls.append((request.block_name, source))
|
||||
return VerifyResult('PASS')
|
||||
dialog = BackupRecoveryDialog(['Beta'],
|
||||
lambda name: VerifyRequest(controls.library, name, controls.library.parent/'evidence'), recoverer=recover)
|
||||
qtbot.addWidget(dialog)
|
||||
dialog.show()
|
||||
with modal_click(qtbot, file=None if cancel else controls.source, cancel_file=cancel):
|
||||
press(qtbot, dialog.browse_button)
|
||||
if cancel:
|
||||
assert dialog.source_edit.text() == ''
|
||||
else:
|
||||
assert Path(dialog.source_edit.text()) == controls.source
|
||||
if cancel:
|
||||
press(qtbot, dialog.restore_button)
|
||||
assert '有效' in dialog.status_label.text() and not dialog.busy
|
||||
else:
|
||||
with modal_click(qtbot, QMessageBox.No):
|
||||
press(qtbot, dialog.restore_button)
|
||||
assert calls == []
|
||||
with modal_click(qtbot, QMessageBox.Yes):
|
||||
press(qtbot, dialog.restore_button)
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
assert calls == [('Beta', controls.source)]
|
||||
assert '恢复完成' in dialog.status_label.text()
|
||||
press(qtbot, dialog.close_button)
|
||||
assert not dialog.isVisible()
|
||||
|
||||
|
||||
def test_recovery_cancel_queue_never_calls_native_restore(controls, qtbot):
|
||||
from cbb_refresh_verify.operation_queue import NativeQueue
|
||||
from cbb_refresh_verify.ui.backup_recovery_dialog import BackupRecoveryDialog
|
||||
calls = []
|
||||
queue = NativeQueue()
|
||||
queue.active = True
|
||||
dialog = BackupRecoveryDialog(['Beta'],
|
||||
lambda name: VerifyRequest(controls.library, name, controls.library.parent/'evidence'),
|
||||
recoverer=lambda *a, **k: calls.append(a))
|
||||
dialog.native_queue = queue
|
||||
qtbot.addWidget(dialog)
|
||||
dialog.show()
|
||||
dialog.source_edit.setText(str(controls.source))
|
||||
with modal_click(qtbot, QMessageBox.Yes):
|
||||
press(qtbot, dialog.restore_button)
|
||||
qtbot.waitUntil(dialog.cancel_queue_button.isEnabled)
|
||||
press(qtbot, dialog.cancel_queue_button)
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
assert calls == [] and dialog.stop.is_set()
|
||||
press(qtbot, dialog.close_button)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('attribute, expected', [('manual_button','last_user_saved'),
|
||||
('auto_button','autosave'), ('cancel_button','cancel')])
|
||||
def test_version_choice_buttons_choose_only_the_clicked_version(qtbot, attribute, expected):
|
||||
from cbb_refresh_verify.pcb_restore_prompt import RestoreChoice
|
||||
from cbb_refresh_verify.ui.pcb_restore_dialog import PcbRestoreDialog
|
||||
choice = RestoreChoice('Beta', 'fixture.lmc', [dict(kind=kind, enabled=True, date='2026/11/11 10:00')
|
||||
for kind in ('last_user_saved','autosave')])
|
||||
dialog = PcbRestoreDialog(choice)
|
||||
qtbot.addWidget(dialog)
|
||||
dialog.show()
|
||||
press(qtbot, getattr(dialog, attribute))
|
||||
assert choice.decision == expected
|
||||
dialog.close()
|
||||
assert choice.decision == expected
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def residual(controls, qtbot, monkeypatch):
|
||||
from cbb_refresh_verify import library_lock, residual_sessions
|
||||
from cbb_refresh_verify.ui.residual_release_dialog import ResidualReleaseDialog
|
||||
row = dict(project='Beta', name='ExpeditionPCB.exe', pid=10, detail='fixture session',
|
||||
scope_confirmed=True, owner_sid='S-1-fixture', session_id=1, force_user_confirmed=True,
|
||||
image='C:/Fixture/ExpeditionPCB.exe', created_handle='fixture-created',
|
||||
native_activity=dict(status='IDLE', detail='fixture returned'),
|
||||
desktops=['CbbFixture'], windows=[dict(title='Fixture native prompt', output='Fixture details')],
|
||||
prompt=dict(text='Save the changed fixture?'), cancel_prompt=dict(text='Cancel fixture'))
|
||||
plan = dict(library=str(controls.library), sessions=[row])
|
||||
state = SimpleNamespace(scans=[], releases=[], cancels=[], saves=[], row=row, plan=plan,
|
||||
entered=Event(), finish=Event(), hold=False)
|
||||
def inspect(library):
|
||||
state.scans.append(library)
|
||||
return plan
|
||||
def release(actual, folder, **kwargs):
|
||||
state.releases.append(kwargs)
|
||||
if state.hold:
|
||||
state.entered.set()
|
||||
assert state.finish.wait(5)
|
||||
return dict(status='PARTIAL', sessions=[dict(row, release_status='WAITING', consent_allowed=True)])
|
||||
def cancel(actual, library, folder, **kwargs):
|
||||
state.cancels.append(actual)
|
||||
return dict(status='PARTIAL', detail='Fixture cancel received',
|
||||
sessions=[dict(row, release_status='WAITING')])
|
||||
monkeypatch.setattr(library_lock, 'inspect_residual_sessions', inspect)
|
||||
monkeypatch.setattr(library_lock, 'release_residual_sessions', release)
|
||||
monkeypatch.setattr(residual_sessions, 'request_native_cancel', cancel)
|
||||
monkeypatch.setattr(residual_sessions, 'answer_save_question',
|
||||
lambda actual, code: state.saves.append((actual['pid'], code)))
|
||||
dialog = ResidualReleaseDialog(controls.library, controls.library.parent/'release-evidence')
|
||||
qtbot.addWidget(dialog)
|
||||
dialog.show()
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
state.dialog = dialog
|
||||
yield state
|
||||
state.finish.set()
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
|
||||
|
||||
def test_residual_refresh_details_confirm_and_close(residual, qtbot):
|
||||
d = residual.dialog
|
||||
press(qtbot, d.refresh_button)
|
||||
qtbot.waitUntil(lambda: not d.busy)
|
||||
assert len(residual.scans) == 2 and d.table.rowCount() == 1
|
||||
press(qtbot, d.details_button)
|
||||
details = d.native_details
|
||||
assert 'Fixture native prompt' in details.detailedText()
|
||||
expand = next(b for b in details.findChildren(QPushButton) if 'Details' in b.text())
|
||||
press(qtbot, expand)
|
||||
assert details.findChild(QTextEdit).isVisible()
|
||||
press(qtbot, details.button(QMessageBox.Ok))
|
||||
press(qtbot, d.confirm_button)
|
||||
qtbot.waitUntil(lambda: not d.busy)
|
||||
assert len(residual.releases) == 1 and residual.releases[0]['force'] is False
|
||||
assert d.table.item(0, 6).text() == '允许'
|
||||
assert d.table.item(0, 7).text() == '未释放'
|
||||
press(qtbot, d.close_button)
|
||||
assert not d.isVisible()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('answer, code', [(QMessageBox.Yes,6),(QMessageBox.No,7),(QMessageBox.Cancel,2)])
|
||||
def test_residual_save_prompt_buttons_preserve_the_users_choice(residual, qtbot, answer, code):
|
||||
d = residual.dialog
|
||||
with modal_click(qtbot, answer):
|
||||
press(qtbot, d.prompt_button)
|
||||
qtbot.waitUntil(lambda: not d.busy)
|
||||
assert residual.saves == [(10, code)]
|
||||
assert d.isVisible() and residual.releases == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize('answer', [QMessageBox.No,QMessageBox.Yes])
|
||||
def test_residual_native_cancel_confirm_and_decline(residual, qtbot, answer):
|
||||
d = residual.dialog
|
||||
with modal_click(qtbot, answer):
|
||||
press(qtbot, d.cancel_native_button)
|
||||
qtbot.waitUntil(lambda: not d.busy)
|
||||
assert len(residual.cancels) == (1 if answer == QMessageBox.Yes else 0)
|
||||
assert residual.releases == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize('answer', [QMessageBox.Cancel,QMessageBox.Yes])
|
||||
def test_residual_force_buttons_require_actual_confirmation(residual, qtbot, answer):
|
||||
d = residual.dialog
|
||||
with modal_click(qtbot, answer):
|
||||
press(qtbot, d.force_button)
|
||||
qtbot.waitUntil(lambda: not d.busy)
|
||||
assert [call['force'] for call in residual.releases] == ([True] if answer == QMessageBox.Yes else [])
|
||||
|
||||
|
||||
def test_residual_busy_repeated_clicks_and_stop_release(residual, qtbot):
|
||||
d = residual.dialog
|
||||
residual.hold = True
|
||||
try:
|
||||
press(qtbot, d.confirm_button)
|
||||
qtbot.waitUntil(residual.entered.is_set)
|
||||
for _ in range(5):
|
||||
qtbot.mouseClick(d.confirm_button, Qt.LeftButton)
|
||||
qtbot.mouseClick(d.refresh_button, Qt.LeftButton)
|
||||
assert len(residual.releases) == 1 and len(residual.scans) == 1
|
||||
press(qtbot, d.close_button)
|
||||
assert d.stop.is_set() and d.isVisible()
|
||||
finally:
|
||||
residual.finish.set()
|
||||
qtbot.waitUntil(lambda: not d.busy)
|
||||
press(qtbot, d.close_button)
|
||||
|
||||
|
||||
def test_result_release_and_resume_buttons_run_only_unexecuted_items(controls, qtbot, monkeypatch):
|
||||
from cbb_refresh_verify import library_lock
|
||||
w = controls.window
|
||||
controls.result = VerifyResult('FAIL', safe_to_continue=False, stderr='Fixture release unconfirmed')
|
||||
with modal_click(qtbot, QMessageBox.Yes):
|
||||
press(qtbot, w.batch_button)
|
||||
qtbot.waitUntil(lambda: not w.busy)
|
||||
assert [request.block_name for request in controls.runs] == ['Beta']
|
||||
assert not w._resume_batch_action.isEnabled()
|
||||
proof = dict(status='RELEASE_CONFIRMED', library=str(controls.library), evidence_path='fixture-proof.json')
|
||||
monkeypatch.setattr(library_lock, 'release_residual_sessions',
|
||||
lambda *a, **k: dict(status='RELEASE_CONFIRMED', proof=proof, sessions=[]))
|
||||
press(qtbot, w._residual_release_action)
|
||||
qtbot.waitUntil(lambda: not w.release_dialog.busy)
|
||||
press(qtbot, w.release_dialog.confirm_button)
|
||||
qtbot.waitUntil(lambda: not w.release_dialog.busy)
|
||||
press(qtbot, w.release_dialog.close_button)
|
||||
qtbot.waitUntil(lambda: not w.busy)
|
||||
controls.result = VerifyResult('PASS')
|
||||
press(qtbot, w._resume_batch_action)
|
||||
qtbot.waitUntil(lambda: not w.busy)
|
||||
assert [request.block_name for request in controls.runs] == ['Beta','Gamma']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('entry', ['icdb_copy', 'icdb_release', 'batch_copy', 'batch_close'])
|
||||
def test_result_recovery_and_release_entries_stay_bound_to_failed_cbb(controls, qtbot, entry):
|
||||
from dataclasses import replace
|
||||
from test_reimport_recovery import failed_repair
|
||||
w = controls.window
|
||||
if entry.startswith('icdb'):
|
||||
tab(qtbot, w, 1)
|
||||
w.search_edit.setText('Beta')
|
||||
controls.result = failed_repair(controls.library.parent/'failure.json', safe=entry=='icdb_copy')
|
||||
with modal_click(qtbot, QMessageBox.Yes):
|
||||
press(qtbot, w.icdb_repair_button)
|
||||
qtbot.waitUntil(lambda: not w._icdb_active())
|
||||
label = '查看残留并释放…' if entry=='icdb_release' else '选择副本恢复…'
|
||||
press(qtbot, next(b for b in w.icdb_summary.buttons() if b.text()==label))
|
||||
else:
|
||||
# This is the supported legacy maintenance-result shape; current UI
|
||||
# maintenance uses the independent IcdbCheckTask route above.
|
||||
req = replace(w._request('Beta'), maintenance=True)
|
||||
w._batch_requests = (req,)
|
||||
w._batch_records = {'Beta':w._records_by_name['Beta']}
|
||||
w._batch_done(([failed_repair(controls.library.parent/'failure.json',safe=True)], None))
|
||||
w._update()
|
||||
if entry=='batch_close':
|
||||
summary = w.summary
|
||||
press(qtbot, summary.button(QMessageBox.Close))
|
||||
assert not isValid(summary) or not summary.isVisible()
|
||||
return
|
||||
press(qtbot, w._reimport_summary_action)
|
||||
if entry=='icdb_release':
|
||||
qtbot.waitUntil(lambda: not w.release_dialog.busy)
|
||||
assert w.release_dialog.library == controls.library
|
||||
press(qtbot, w.release_dialog.close_button)
|
||||
else:
|
||||
dialog = w.management_dialog
|
||||
assert [req.name for req in dialog.requests()] == ['Beta']
|
||||
assert Path(dialog.recovery_from['Beta']) == controls.library.parent/'failure.json'
|
||||
press(qtbot, dialog.close_button)
|
||||
qtbot.waitUntil(lambda: not w.busy)
|
||||
if entry=='icdb_copy':
|
||||
tab(qtbot,w,1)
|
||||
press(qtbot,w.reimport_button)
|
||||
assert [req.name for req in w.management_dialog.requests()] == ['Beta']
|
||||
press(qtbot,w.management_dialog.close_button)
|
||||
|
||||
|
||||
def test_invalidated_catalog_buttons_ignore_clicks(controls, qtbot):
|
||||
w = controls.window
|
||||
w.lmc_edit.setText('not-loaded.lmc')
|
||||
for index, attributes in [(0,['selected_batch_button','batch_button']),
|
||||
(1,['icdb_repair_button','native_backup_button','backup_restore_button']),
|
||||
(2,['add_button','update_button','remove_button'])]:
|
||||
tab(qtbot,w,index)
|
||||
for attribute in attributes:
|
||||
button = getattr(w,attribute)
|
||||
assert not button.isEnabled()
|
||||
qtbot.mouseClick(button,Qt.LeftButton)
|
||||
assert controls.runs == [] and controls.native == []
|
||||
assert getattr(w,'management_dialog',None) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('attribute, failure', [('logs_button','shell'),
|
||||
('logs_button','directory'),('recovery_button','shell')])
|
||||
def test_log_and_evidence_buttons_report_external_failure(controls,qtbot,monkeypatch,attribute,failure):
|
||||
import cbb_refresh_verify.ui.main_window as ui
|
||||
def fail(path):
|
||||
raise OSError('Fixture shell access denied')
|
||||
w = controls.window
|
||||
if failure=='shell':
|
||||
monkeypatch.setattr(ui.os,'startfile',fail)
|
||||
expected = 'Fixture shell access denied'
|
||||
else:
|
||||
w.data_root = controls.source/'logs'
|
||||
expected = 'Beta.prj'
|
||||
if attribute=='recovery_button':
|
||||
w.recovery_path = controls.library.parent
|
||||
w.recovery_button.setEnabled(True)
|
||||
press(qtbot,getattr(w,attribute))
|
||||
assert expected in w.status_label.text()
|
||||
assert controls.opened == []
|
||||
Reference in new issue
Block a user