Per-window installs of the two QApplication-level filters (cursor, wheel guard) stacked one stale copy per MainWindow; now installed once per process, parented to the app. closeEvent overrides in the baton dialogs replaced by finished.connect(timer.stop); keyPressEvent in VideoGraphicsView replaced by WidgetShortcut QShortcuts; hover enter/leave overrides in PlayPauseButton replaced by underMouse(); ValueLabel inherits ClickableLabel instead of duplicating its mousePressEvent. Dead raster-timer branch and a PyQt5-era event-position fallback deleted; redundant try/except and getattr guards dropped now that class-level defaults cover pre-init reads. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
104 lines
3.5 KiB
Python
104 lines
3.5 KiB
Python
"""Covers the code paths touched by the reduce-overwriting-qt-method
|
|
refactor: Qt-native replacements (signals, shortcuts, underMouse) for
|
|
virtual-method overrides, so the diff-coverage gate sees them executed."""
|
|
|
|
from PySide6.QtCore import QEvent, QPointF, Qt
|
|
from PySide6.QtGui import QMouseEvent
|
|
|
|
from aare.gui.panels.fluorescence_panel import FluorescencePanel
|
|
from aare.gui.panels.portrait_mode import PlayPauseButton
|
|
from aare.gui.widgets.baton_request_dialog import BatonPendingDialog, BatonRequestDialog
|
|
from aare.gui.widgets.value_label import ValueLabel
|
|
from aare.gui.widgets.video_image import VideoGraphicsView
|
|
|
|
|
|
def test_baton_dialogs_stop_timer_via_finished(qtbot):
|
|
"""finished.connect replaced the closeEvent overrides: the timer must
|
|
stop on accept, reject AND plain close — the path closeEvent used to
|
|
handle."""
|
|
req = BatonRequestDialog("someone")
|
|
qtbot.addWidget(req)
|
|
assert req._timer.isActive()
|
|
req._on_accept()
|
|
assert not req._timer.isActive()
|
|
|
|
req2 = BatonRequestDialog("someone")
|
|
qtbot.addWidget(req2)
|
|
req2._on_refuse()
|
|
assert not req2._timer.isActive()
|
|
|
|
# close() only delivers a close event to a SHOWN dialog — same held for
|
|
# the old closeEvent override, so showing first keeps the test honest.
|
|
pend = BatonPendingDialog("user")
|
|
qtbot.addWidget(pend)
|
|
pend.show()
|
|
qtbot.waitExposed(pend)
|
|
assert pend._timer.isActive()
|
|
pend.close()
|
|
assert not pend._timer.isActive()
|
|
|
|
|
|
def test_fluorescence_hover_snaps_to_peak(qtbot):
|
|
"""Drives a MouseMove through the viewport filter: event.position()
|
|
(the PyQt5-era hasattr fallback is gone) and the max(range) peak snap."""
|
|
panel = FluorescencePanel()
|
|
qtbot.addWidget(panel)
|
|
panel.resize(500, 400)
|
|
panel.show()
|
|
qtbot.waitExposed(panel)
|
|
|
|
panel.axis_x.setRange(0.0, 10.0)
|
|
panel.axis_y.setRange(0.0, 100.0)
|
|
for i in range(50):
|
|
panel.series.append(i * 0.2, 90.0 if i == 25 else 10.0)
|
|
|
|
plot = panel.chart.plotArea()
|
|
pos = QPointF(plot.center())
|
|
ev = QMouseEvent(
|
|
QEvent.Type.MouseMove,
|
|
pos,
|
|
panel.chart_view.viewport().mapToGlobal(pos.toPoint()),
|
|
Qt.MouseButton.NoButton,
|
|
Qt.MouseButton.NoButton,
|
|
Qt.KeyboardModifier.NoModifier,
|
|
)
|
|
assert panel.eventFilter(panel.chart_view.viewport(), ev) is False
|
|
assert "keV" in panel.chart_view.toolTip()
|
|
|
|
|
|
def test_video_view_shortcuts_replace_keypress_override(qtbot):
|
|
view = VideoGraphicsView()
|
|
qtbot.addWidget(view)
|
|
view.show()
|
|
qtbot.waitExposed(view)
|
|
# WidgetShortcut context needs real focus; offscreen grants it only
|
|
# after the window is active.
|
|
view.activateWindow()
|
|
view.setFocus()
|
|
qtbot.waitUntil(view.hasFocus, timeout=2000)
|
|
|
|
qtbot.keyClick(view, Qt.Key.Key_Plus)
|
|
assert view.zoom_factor > 1.0
|
|
qtbot.keyClick(view, Qt.Key.Key_R)
|
|
assert view.zoom_factor == 1.0
|
|
qtbot.keyClick(view, Qt.Key.Key_Minus)
|
|
assert view.zoom_factor < 1.0
|
|
qtbot.keyClick(view, Qt.Key.Key_F) # fit_to_view: just must not raise
|
|
|
|
|
|
def test_play_pause_button_paints_without_hover_overrides(qtbot):
|
|
btn = PlayPauseButton()
|
|
qtbot.addWidget(btn)
|
|
btn.set_running(True)
|
|
# grab() forces a real paintEvent pass over the underMouse() branch
|
|
assert not btn.grab().isNull()
|
|
|
|
|
|
def test_value_label_inherits_click(qtbot):
|
|
label = ValueLabel("Energy", "keV")
|
|
qtbot.addWidget(label)
|
|
label.set_value("12.4")
|
|
assert "12.4" in label.text()
|
|
with qtbot.waitSignal(label.clicked, timeout=1000):
|
|
qtbot.mousePress(label, Qt.MouseButton.LeftButton)
|