update sensor bench
This commit is contained in:
+123
-52
@@ -35,10 +35,13 @@ def test_translator_chinese_default() -> None:
|
||||
assert DEFAULT_LOCALE == "zh_CN"
|
||||
tr = Translator(default_locales_dir())
|
||||
assert tr.locale == "zh_CN"
|
||||
assert "传感器" in tr.t("app.title")
|
||||
assert "传感器" in tr.t("app.title") or "展示" in tr.t("exhibition.title")
|
||||
tr.set_locale("en_US")
|
||||
assert tr.t("app.title") == "Sensor Bench"
|
||||
assert "Power on" in tr.step_title("power_on")
|
||||
assert "Exhibition" in tr.t("exhibition.title")
|
||||
# Public locales must not ship internal inspection workflow copy.
|
||||
assert "workflow" not in (tr._catalogs.get("en_US") or {})
|
||||
assert tr._lookup("en_US", "workflow.title") is None
|
||||
|
||||
|
||||
def test_sdk_worker_packet_mapping() -> None:
|
||||
@@ -65,6 +68,9 @@ def test_sdk_worker_packet_mapping() -> None:
|
||||
def read_info(self, *args):
|
||||
return 1.0, 2.0, 3.0
|
||||
|
||||
def configure(self, **kwargs):
|
||||
return self
|
||||
|
||||
def disconnect(self):
|
||||
pass
|
||||
|
||||
@@ -102,65 +108,127 @@ def test_sdk_worker_packet_mapping() -> None:
|
||||
assert packet.processed_frame.shape[:2] == (365, 365)
|
||||
|
||||
|
||||
def test_mainwindow_offscreen() -> None:
|
||||
def test_force_calibration_and_plot_min_span() -> None:
|
||||
from sensor_bench.force_calibration import (
|
||||
NORMAL_FORCE_CAL_OFFSET,
|
||||
Y_AXIS_MIN_SPAN,
|
||||
calibrate_normal_force,
|
||||
)
|
||||
from sensor_bench.plot_history import MetricHistory
|
||||
|
||||
assert abs(calibrate_normal_force(0.0) - NORMAL_FORCE_CAL_OFFSET) < 1e-12
|
||||
hist = MetricHistory(
|
||||
npoints=8,
|
||||
channels=3,
|
||||
window_sec=1.0,
|
||||
sample_rate_hz=30.0,
|
||||
lowpass_cutoff_hz=0.0,
|
||||
y_axis_min_span=Y_AXIS_MIN_SPAN,
|
||||
y_range_alpha=0.5,
|
||||
)
|
||||
for i in range(5):
|
||||
hist.push(float(i) / 30.0, 100.0, 100.0, 100.0)
|
||||
state = hist.state()
|
||||
assert state is not None
|
||||
for ymin, ymax in state.y_ranges:
|
||||
assert (ymax - ymin) >= Y_AXIS_MIN_SPAN * 0.99
|
||||
|
||||
|
||||
def test_list_orisys_configs_excludes_options() -> None:
|
||||
from sensor_bench.paths import (
|
||||
config_display_name,
|
||||
list_local_sensor_config_files,
|
||||
list_orisys_configs,
|
||||
local_sensor_configs_dir,
|
||||
)
|
||||
|
||||
entries = list_orisys_configs()
|
||||
labels = [config_display_name(e).lower() for e in entries]
|
||||
assert "options" not in labels
|
||||
assert all(Path(e).stem.lower() != "options" for e in entries if Path(e).suffix.lower() == ".json")
|
||||
|
||||
local_ddjx = local_sensor_configs_dir() / "ddjx01.json"
|
||||
if local_ddjx.exists():
|
||||
local_files = list_local_sensor_config_files()
|
||||
assert any(p.name == "ddjx01.json" for p in local_files)
|
||||
assert any(config_display_name(e).lower() == "ddjx01" for e in entries)
|
||||
|
||||
|
||||
def test_roi_geometry_helpers() -> None:
|
||||
from sensor_bench.roi_geometry import build_roi_warp, order_quad_points, warp_roi_to_rectangle
|
||||
import numpy as np
|
||||
|
||||
points = np.array([[10, 10], [100, 12], [98, 90], [12, 88]], dtype=np.float32)
|
||||
ordered = order_quad_points(points)
|
||||
assert ordered.shape == (4, 2)
|
||||
matrix, src, size = build_roi_warp(points, (120, 100), (120, 100), (64, 64))
|
||||
assert size == (64, 64)
|
||||
assert src.shape == (4, 2)
|
||||
frame = np.zeros((100, 120, 3), dtype=np.uint8)
|
||||
out = warp_roi_to_rectangle(frame, matrix, size)
|
||||
assert out.shape == (64, 64, 3)
|
||||
|
||||
|
||||
def test_exhibition_window_offscreen() -> None:
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from sensor_bench.app import MainWindow
|
||||
from sensor_bench.acquisition import FixedCameraMode
|
||||
from sensor_bench.exhibition_app import ExhibitionWindow
|
||||
from sensor_bench.i18n import DEFAULT_LOCALE
|
||||
|
||||
app = QApplication.instance() or QApplication([])
|
||||
win = MainWindow()
|
||||
win = ExhibitionWindow()
|
||||
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.btn_next is not None
|
||||
assert win.btn_revert is not None
|
||||
assert "展示" in win.windowTitle() or "Sensor Bench" in win.windowTitle()
|
||||
assert win.btn_start is not None
|
||||
assert win.btn_stop 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()
|
||||
assert win.btn_record is not None
|
||||
assert win.btn_search is not None
|
||||
assert win.btn_camera is not None
|
||||
assert not hasattr(win, "btn_cal")
|
||||
assert not hasattr(win, "cal_edit")
|
||||
assert win.btn_reset.text() == "重置"
|
||||
assert win.image_label is not None
|
||||
assert win.log_widget is not None
|
||||
assert not win.show_log_check.isChecked()
|
||||
assert win.log_widget.isHidden()
|
||||
assert win.show_log_check.text() == "显示日志面板"
|
||||
win.show_log_check.setChecked(True)
|
||||
assert win._log_panel_visible
|
||||
assert not win.log_widget.isHidden()
|
||||
win.show_log_check.setChecked(False)
|
||||
assert win.log_widget.isHidden()
|
||||
assert not win._log_panel_visible
|
||||
assert len(win.plots) == 3
|
||||
assert len(win.curves) == 3
|
||||
assert win.btn_start.text() == "启动"
|
||||
assert not win.btn_stop.isEnabled()
|
||||
assert win._view_mode == "pure_color"
|
||||
assert win.view_combo.currentData() == "pure_color"
|
||||
assert win.about_action is not None
|
||||
assert win.help_menu is not None
|
||||
assert win.sensor_combo.count() == 2
|
||||
assert win.config_combo is not None
|
||||
assert win.config_combo.count() >= 1
|
||||
from sensor_bench.paths import list_orisys_configs
|
||||
|
||||
installed = list_orisys_configs()
|
||||
if "ddjx01" in installed:
|
||||
assert win.config_combo.currentData() == "ddjx01" or win._selected_config() == "ddjx01"
|
||||
|
||||
# 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"
|
||||
assert "Exhibition" in win.windowTitle()
|
||||
assert win.btn_start.text() == "Start"
|
||||
assert win.btn_reset.text() == "Reset"
|
||||
assert win.show_log_check.text() == "Show log panel"
|
||||
assert "About" in win.about_action.text()
|
||||
|
||||
# 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.view_combo.setCurrentIndex(1)
|
||||
assert win._view_mode == "captured"
|
||||
win.sensor_combo.setCurrentIndex(1)
|
||||
assert win._sensor_type == "dd06"
|
||||
selected = str(win._selected_config()).lower()
|
||||
assert "dd06" in selected or selected.endswith(".json")
|
||||
win.close()
|
||||
|
||||
|
||||
@@ -168,5 +236,8 @@ if __name__ == "__main__":
|
||||
test_load_fixed_mode()
|
||||
test_translator_chinese_default()
|
||||
test_sdk_worker_packet_mapping()
|
||||
test_mainwindow_offscreen()
|
||||
test_force_calibration_and_plot_min_span()
|
||||
test_list_orisys_configs_excludes_options()
|
||||
test_roi_geometry_helpers()
|
||||
test_exhibition_window_offscreen()
|
||||
print("ok")
|
||||
|
||||
Reference in New Issue
Block a user