83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
"""Smoke tests for the internal Sensor Bench operator UI."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT / "src"))
|
|
sys.path.insert(0, str(ROOT / "internal" / "src"))
|
|
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
|
|
|
|
def test_mainwindow_offscreen() -> None:
|
|
from PyQt5.QtWidgets import QApplication
|
|
from sensor_bench.acquisition import FixedCameraMode
|
|
from sensor_bench.i18n import DEFAULT_LOCALE
|
|
from sensor_bench_operator.app import MainWindow
|
|
|
|
app = QApplication.instance() or QApplication([])
|
|
win = MainWindow()
|
|
assert win.tr.locale == DEFAULT_LOCALE == "zh_CN"
|
|
assert "传感器" in win.windowTitle()
|
|
assert win.btn_start.text() == "开始预览"
|
|
assert win.camera_index.value() == 0
|
|
assert win.config_combo is not None
|
|
assert win.config_combo.count() >= 1
|
|
assert win.btn_next is not None
|
|
assert win.btn_revert is not None
|
|
assert win.btn_reset is not None
|
|
assert win.sensor_type_combo.count() == 2
|
|
assert win.indentor_combo.count() == 2
|
|
assert win.platform_combo.count() == 3
|
|
assert win.selected_sensor_options()["sensor_type"] == "BOX"
|
|
assert win.selected_sensor_options()["indentor"] == "1mm_circle"
|
|
assert win.selected_sensor_options()["platform"] == "manual"
|
|
assert not hasattr(win, "resolution_combo")
|
|
assert not hasattr(win, "btn_search")
|
|
assert win._current_step_index == 0
|
|
assert not win.btn_revert.isEnabled()
|
|
assert win.btn_next.isEnabled()
|
|
|
|
# Language switch refreshes labels without restart.
|
|
win.language_combo.setCurrentIndex(1)
|
|
assert win.tr.locale == "en_US"
|
|
assert win.windowTitle() == "Sensor Bench"
|
|
assert win.btn_start.text() == "Start Preview"
|
|
|
|
# Workflow next / revert / reset.
|
|
total = len(win.workflow.steps)
|
|
win._on_step_next()
|
|
assert win._current_step_index == 1
|
|
assert win.btn_revert.isEnabled()
|
|
win._on_step_revert()
|
|
assert win._current_step_index == 0
|
|
for _ in range(total):
|
|
win._on_step_next()
|
|
assert win._current_step_index == total
|
|
assert not win.btn_next.isEnabled()
|
|
assert "completed" in win.workflow_status.text().lower() or "完成" in win.workflow_status.text()
|
|
win._on_step_reset()
|
|
assert win._current_step_index == 0
|
|
assert win.btn_next.isEnabled()
|
|
|
|
win._fixed_mode = FixedCameraMode(
|
|
width=1920,
|
|
height=1080,
|
|
fps=30.0,
|
|
config_ref=str(ROOT / "tests" / "fixtures" / "ddjx01_min.json"),
|
|
stitch_width=365,
|
|
stitch_height=365,
|
|
)
|
|
win.mode_label.setText(win.t("labels.fixed_mode", mode=win._fixed_mode.label()))
|
|
assert "1920x1080" in win.mode_label.text()
|
|
win.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_mainwindow_offscreen()
|
|
print("ok")
|