Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions tests/test_find_in_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path
import re
import pytest
from PySide6.QtCore import QCoreApplication, QEvent, QEventLoop, QTimer
from PySide6.QtWidgets import QApplication

from core.file_search import (
Expand All @@ -31,6 +32,30 @@ def qapp():
yield app


def _wait_for_signal(signal, already_done, timeout_ms: int = 5000) -> None:
"""Wartet ohne pytest-qt, bis ``signal`` im GUI-Thread zugestellt wurde."""
loop = QEventLoop()
fired = []

def _on_signal(*_args):
fired.append(True)
loop.quit()

signal.connect(_on_signal)
timer = QTimer()
timer.setSingleShot(True)
timer.timeout.connect(loop.quit)
timer.start(timeout_ms)
try:
if not already_done():
loop.exec()
QCoreApplication.processEvents()
finally:
timer.stop()
signal.disconnect(_on_signal)
assert fired or already_done(), "Signal wurde nicht innerhalb des Timeouts zugestellt"


def test_compile_search_regex():
# 1. Plain text case-insensitive
opts = SearchOptions(query="codebox", case_sensitive=False)
Expand Down Expand Up @@ -237,10 +262,13 @@ def test_find_in_files_dialog_ui_and_jump(qapp, tmp_path: Path):
dlg.search_input.setText("target_keyword")
dlg.start_search()

# Wait for background worker to complete
if dlg._worker:
dlg._worker.wait(3000)
qapp.processEvents()
# Auf das zugestellte searchFinished-Signal warten statt den GUI-Thread mit
# QThread.wait() zu blockieren und danach alle gequeuten Signale auf einmal
# per processEvents() abzuarbeiten (nativer Access-Violation-Flake unter
# Windows/Python 3.10, CI-Job 119632528992).
assert dlg._worker is not None
_wait_for_signal(dlg._worker.searchFinished, dlg._worker.isFinished)
dlg._worker.wait(3000)

# Verify results in tree
assert dlg.results_tree.topLevelItemCount() == 1
Expand Down Expand Up @@ -271,6 +299,10 @@ def test_find_in_files_dialog_ui_and_jump(qapp, tmp_path: Path):

dlg.close()
win.close()
dlg.deleteLater()
win.deleteLater()
QCoreApplication.sendPostedEvents(None, QEvent.Type.DeferredDelete)
qapp.processEvents()


def test_main_window_show_find_in_files(qapp, tmp_path: Path):
Expand Down
Loading