Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion mantidimaging/gui/test/gui_system_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtTest import QTest
from PyQt5.QtWidgets import QApplication, QMessageBox, QInputDialog
from PyQt5.QtWidgets import QApplication, QMessageBox, QInputDialog, QDialog
import pytest

from mantidimaging.core.utility.leak_tracker import leak_tracker
Expand Down Expand Up @@ -43,6 +43,8 @@ def tearDown(self) -> None:
Will report any leaked images
Expects all other windows to be closed, otherwise will raise a RuntimeError
"""
self._check_no_open_dialogs()

QTimer.singleShot(SHORT_DELAY, lambda: self._click_messageBox("Yes"))
self.main_window.close()
QTest.qWait(SHORT_DELAY)
Expand All @@ -57,6 +59,16 @@ def tearDown(self) -> None:
if widget.isVisible():
RuntimeError(f"\n\nWindow still open {widget=}")

@classmethod
def _check_no_open_dialogs(cls) -> None:
QTest.qWait(SHORT_DELAY)
for widget in cls.app.topLevelWidgets():
if widget.isVisible():
if isinstance(widget, QMessageBox):
raise RuntimeError(f"QMessageBox is visible: {widget.text()}")
if isinstance(widget, QDialog):
raise RuntimeError(f"QDialog is visible: {widget.windowTitle()}")

@classmethod
def _click_messageBox(cls, button_text: str):
"""Needs to be queued with QTimer.singleShot before triggering the message box"""
Expand Down
7 changes: 4 additions & 3 deletions mantidimaging/gui/test/gui_system_loading_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def test_replace_image_stack(self, mocked_select_file):
self._load_data_set()
self.assertEqual(len(self.main_window.presenter.get_active_stack_visualisers()), 5)
self.assertEqual(100, list(self.main_window.presenter.datasets)[0].sample.data.shape[0])
initial_sample_id = list(self.main_window.presenter.datasets)[0].sample.id

self.main_window.dataset_tree_widget.topLevelItem(0).setSelected(True)
self._check_datasets_consistent()
Expand All @@ -248,13 +249,13 @@ def test_replace_image_stack(self, mocked_select_file):
gofn.return_value = (str(new_stack), None)
self.main_window.add_to_dataset_dialog.chooseFileButton.click()

self.main_window.add_to_dataset_dialog.accepted.emit()
QTest.qWait(SHORT_DELAY)
self.main_window.add_to_dataset_dialog.accept()
wait_until(lambda: initial_sample_id not in self.main_window.presenter.all_stack_ids)

self._check_datasets_consistent()
self.assertEqual(20, list(self.main_window.presenter.datasets)[0].sample.data.shape[0])

def _check_datasets_consistent(self, show_datasets=False) -> None:
print("_check_datasets_consistent")
if show_datasets:
print("Main window datasets")
for k, v in self.main_window.presenter.model.datasets.items():
Expand Down
Loading