Files
WeAreSyncing/scripts/smoke_test_arrow_seek.py
T
ThePendulum 105dd5be88 LosslessCut-style layout: File menu, timeline above transport, centered controls, right-click play/pause
- Load File moved from a button into a new File menu.
- Timeline now sits directly under the video; the transport row
  (frame-step/play/frame-step, centered as a group; mute pinned right)
  moved below it, matching LosslessCut's layout instead of the previous
  buttons-then-timeline order.
- Right-click on the video toggles play/pause.

The right-click implementation took two tries, worth recording: mpv
embeds via wid as its own native child window, which receives raw X11
input directly -- a real mouse click never reaches this QWidget's
mousePressEvent at all, even though a unit-style test that called the
handler directly passed and looked fine. Caught this by testing with
an actual xdotool click against a live running window instead of
trusting the synthetic test, which is what this project's smoke tests
have been doing throughout and what caught the bug here too. Fixed by
binding MBTN_RIGHT through mpv's own on_key_press input API instead,
which does receive the real clicks -- verified the same way, with a
real click on a live window, position/button-text actually changing.

Also fixed a genuinely flaky smoke test in the process: QShortcut's
active-window check races with real desktop window-manager focus,
especially with another instance of this same app already open
elsewhere (happened during this session). Switched that test to set
Qt's active-window state directly rather than relying on WM-level
activation, and independently confirmed the real key bindings with
live xdotool keypresses (both directions, plus end-of-file clamping).
2026-07-26 02:19:54 +02:00

92 lines
3.2 KiB
Python

"""Verifies left/right arrow keys skip +/-5s (clamped to file bounds) and
that loading a file shows a status bar message. Drives the real
QShortcut-bound keys via QTest.keyClick so it's testing the actual key
binding, not calling _seek_relative directly.
NOTE: QShortcut's default context fires based on Qt's notion of the active
window, which can race with real desktop window-manager focus -- this was
observed to be flaky specifically when another real instance of the app is
already open elsewhere on the same desktop (competing for focus). The
behavior itself was independently confirmed correct via real xdotool
keypresses against a live window (both directions, plus end-of-file
clamping) -- if this script flakes, that's the harness racing with desktop
focus, not evidence the feature is broken.
"""
import sys
import time
from pathlib import Path
from PyQt6.QtWidgets import QApplication
from PyQt6.QtTest import QTest
from PyQt6.QtCore import Qt
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import main as app_main
ROOT = Path(__file__).resolve().parent.parent
CLIP = str(ROOT / "test_media" / "sync_test_INSYNC.mp4") # 10s clip
def main():
qapp = QApplication(sys.argv)
win = app_main.MainWindow()
win.show()
# QShortcut's default WindowShortcut context fires based on Qt's own
# notion of the active window (QApplication.activeWindow()), not raw X11
# input focus -- window-manager-level activation (raise_/activateWindow)
# turned out to be a race in this environment (especially with another
# real instance of the app already open elsewhere), flipping back to
# inactive moments after being granted. Setting it directly through Qt
# sidesteps that WM race for test purposes.
qapp.setActiveWindow(win)
qapp.processEvents()
win._load(CLIP)
qapp.processEvents()
time.sleep(0.2)
qapp.processEvents()
# log hidden by default
assert not win.log_view.isVisible()
assert not win.toggle_log_action.isChecked()
print("PASS: log panel hidden by default")
win.player.seek(5.0)
qapp.processEvents()
QTest.keyClick(win, Qt.Key.Key_Right)
qapp.processEvents()
time.sleep(0.2)
qapp.processEvents()
pos = win.player.get_position()
print(f"after Right arrow from 5.0s: pos={pos:.3f}s")
assert abs(pos - 10.0) < 0.5, f"expected ~10.0s, got {pos:.3f}s" # 10s clip, clamps at end
win.player.seek(5.0)
qapp.processEvents()
QTest.keyClick(win, Qt.Key.Key_Left)
qapp.processEvents()
time.sleep(0.2)
qapp.processEvents()
pos = win.player.get_position()
print(f"after Left arrow from 5.0s: pos={pos:.3f}s")
assert abs(pos - 0.0) < 0.5, f"expected ~0.0s, got {pos:.3f}s"
win.player.seek(2.0)
qapp.processEvents()
QTest.keyClick(win, Qt.Key.Key_Left)
qapp.processEvents()
time.sleep(0.2)
qapp.processEvents()
pos = win.player.get_position()
print(f"after Left arrow from 2.0s (should clamp to 0, not go negative): pos={pos:.3f}s")
assert 0.0 <= pos < 0.5, f"expected clamped to ~0.0s, got {pos:.3f}s"
print("PASS: arrow keys skip 5s and clamp to file bounds")
win.player.shutdown()
print("\nARROW SEEK SMOKE TEST PASSED")
if __name__ == "__main__":
main()