Files
ai-challenge-tool/tests/test_viewer.py
T
ScriptSorcerer d3a7f8b07e
Tests / tests (push) Failing after 19s
Tests: Qt am Ende geordnet herunterfahren
Unter Linux stürzte PySide6 nach bestandenen Tests beim Beenden ab
(Fatal Python error: none_dealloc), weil Python beim Aufräumen noch
lebende Qt-Fenster in falscher Reihenfolge löschte. Fenster werden jetzt
nach jedem Test gelöscht, und am Ende der Session wird Qt mit
QApplication.shutdown() beendet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:45:20 +01:00

170 lines
6.0 KiB
Python

"""Schritte 2 bis 7 im Fenster (viewer.py): Tasten, Abspielen, Kurven,
Markieren/Löschen, Filter-Panel, Hilfe und Export-Ablauf."""
import pytest
from PySide6.QtCore import QPointF, Qt
from PySide6.QtTest import QTest
from PySide6.QtWidgets import QMessageBox, QSplitter
import viewer
from conftest import delete_widget, press, wait_until
from dataset import load_dataset
@pytest.fixture
def window(make_recording):
"""Fenster mit 40 Frames: Speed 0 am Start, eine Rechtskurve mit 0°-Ausreisser bei 21, Frame 30 unscharf."""
angles = [0.0] * 10 + [15.0] * 10 + [0.0] + [15.0] * 9 + [-5.0] * 10
speeds = [0, 0, 0] + [30] * 37
w = viewer.ViewerWindow(load_dataset(make_recording(angles, speeds=speeds, blurry={30})))
w.show()
w.activateWindow()
QTest.qWait(100)
yield w
delete_widget(w)
def test_keys_navigate(window):
press(window, Qt.Key_Right)
press(window, Qt.Key_Right)
assert window.index == 2 and window.slider.value() == 2
press(window, Qt.Key_Right, Qt.ShiftModifier)
assert window.index == 2 + viewer.RECORDING_FPS
press(window, Qt.Key_End)
assert window.index == 39
press(window, Qt.Key_Right) # bleibt am Ende
assert window.index == 39
press(window, Qt.Key_Home)
assert window.index == 0
window.slider.setValue(17)
assert window.index == 17
def test_info_line_shows_values(window):
window.show_frame(12)
assert "Frame 12" in window.info_label.text() and "+15.0°" in window.info_label.text()
def test_play_runs_to_end_and_stops(window):
window.set_play_fps(600)
press(window, Qt.Key_Space)
assert window.play_timer.isActive()
assert wait_until(lambda: not window.play_timer.isActive())
assert window.index == 39 and "Abspielen" in window.play_button.text()
def test_play_fps_steps(window):
window.set_play_fps(15)
press(window, Qt.Key_Plus)
assert window.play_fps == 20
press(window, Qt.Key_Minus)
press(window, Qt.Key_Minus)
assert window.play_fps == 10
def test_image_fills_label_and_follows_splitter(window):
label, pixmap = window.image_label, window.image_label.pixmap()
assert pixmap.height() == label.height() or pixmap.width() == label.width()
window.findChild(QSplitter).setSizes([250, 500])
QTest.qWait(50)
assert window.image_label.pixmap().height() == window.image_label.height()
def test_click_in_curve_jumps(window):
plot = window.curves.angle_plot
y = sum(plot.vb.viewRange()[1]) / 2
pos = window.curves.mapFromScene(plot.vb.mapViewToScene(QPointF(25, y)))
QTest.mouseClick(window.curves.viewport(), Qt.LeftButton, pos=pos)
QTest.qWait(20)
assert window.index == 25 and window.curves.cursor_lines[0].value() == 25
def test_mark_delete_undo(window):
window.show_frame(5)
press(window, Qt.Key_Q)
for _ in range(3):
press(window, Qt.Key_Right)
press(window, Qt.Key_E)
assert window.marked_range() == (5, 8)
press(window, Qt.Key_Delete)
assert window.deletions.count(window.dataset.frames) == 4
assert window.marked_range() is None
assert "GELÖSCHT" in window.info_label.text()
assert window.deleted_label.text() == "Gelöscht: 4 von 40 Frames"
press(window, Qt.Key_Z, Qt.ControlModifier)
assert window.deletions.count(window.dataset.frames) == 0
press(window, Qt.Key_Y, Qt.ControlModifier)
assert window.deletions.count(window.dataset.frames) == 4
def test_bracket_with_altgr_and_open_range(window):
window.show_frame(20)
QTest.keyClick(window, "[", Qt.ControlModifier | Qt.AltModifier) # AltGr wie auf CH-Tastatur
window.show_frame(24)
assert window.marked_range() == (20, 24) # nur Anfang: bis aktuell
press(window, Qt.Key_Escape)
assert window.marked_range() is None
def test_delete_without_marking_and_restore(window):
window.show_frame(3)
press(window, Qt.Key_Delete)
assert window.deletions.count(window.dataset.frames) == 1
press(window, Qt.Key_Backspace)
assert window.deletions.count(window.dataset.frames) == 0
def test_help_panel(window):
assert not window.help_panel.isVisible()
press(window, Qt.Key_F1)
assert window.help_panel.isVisible()
assert "Anfang des Bereichs" in window.help_panel.text()
press(window, Qt.Key_F1)
assert not window.help_panel.isVisible()
def test_filter_panel_preview_jump_and_delete(window):
panel = window.filter_panel
rows = {spec.title: (box, spin) for spec, box, spin, _ in panel.rows}
press(window, Qt.Key_F)
assert panel.isVisible()
rows["Speed ≤ X"][0].setChecked(True)
assert window.preview == [0, 1, 2]
rows["0°-Ausreisser"][0].setChecked(True)
assert window.preview == [0, 1, 2, 20]
rows["Unscharf"][0].setChecked(True)
assert window.preview == [0, 1, 2, 20, 30]
assert len(window.curves.preview_regions) > 0
window.show_frame(2)
press(window, Qt.Key_N)
assert window.index == 20 and "0°-Ausreisser" in window.info_label.text()
press(window, Qt.Key_N, Qt.ShiftModifier)
assert window.index == 2
QTest.mouseClick(panel.delete_button, Qt.LeftButton)
assert window.deletions.count(window.dataset.frames) == 5
assert not panel.delete_button.isEnabled()
press(window, Qt.Key_Z, Qt.ControlModifier) # alles in einem Schritt zurück
assert window.deletions.count(window.dataset.frames) == 0
press(window, Qt.Key_F)
assert not panel.isVisible() and window.preview == []
def test_export_flow(window, tmp_path, monkeypatch):
answers = iter(["Exportieren", "OK"])
def fake_exec(box): # klickt im Dialog automatisch den gewünschten Knopf
wanted = next(answers)
[b for b in box.buttons() if b.text().replace("&", "") == wanted][0].click()
return 0
monkeypatch.setattr(QMessageBox, "exec", fake_exec)
monkeypatch.setattr(viewer, "EXPORT_DIR", tmp_path / "export")
window.deletions.delete(window.dataset.frames[:3])
window.export_data()
target = tmp_path / "export" / "aufnahme_bereinigt"
assert len(list(target.glob("*.jpg"))) == 37