From 83318c2f94a925678f9ae12973a0cc31743068b2 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Wed, 25 Aug 2021 12:02:19 +0100 Subject: [PATCH] Add gui system tests for reconstruction Some tests for the tilt/COR interface test_refine_stress can be used to trigger #1110 so is set to skip. --- mantidimaging/gui/test/gui_system_base.py | 14 ++- .../test/test_gui_system_reconstruction.py | 86 +++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 mantidimaging/gui/test/test_gui_system_reconstruction.py diff --git a/mantidimaging/gui/test/gui_system_base.py b/mantidimaging/gui/test/gui_system_base.py index 78344308b9c..9e988abdfff 100644 --- a/mantidimaging/gui/test/gui_system_base.py +++ b/mantidimaging/gui/test/gui_system_base.py @@ -3,13 +3,13 @@ import os from pathlib import Path -from typing import Callable +from typing import Callable, Optional import unittest from unittest import mock from PyQt5.QtCore import Qt, QTimer from PyQt5.QtTest import QTest -from PyQt5.QtWidgets import QApplication, QMessageBox +from PyQt5.QtWidgets import QApplication, QMessageBox, QInputDialog import pytest from mantidimaging.core.utility.version_check import versions @@ -55,6 +55,16 @@ def _click_messageBox(cls, button_text: str): button_texts = [button.text() for button in widget.buttons()] raise ValueError(f"Could not find button '{button_text}' in {button_texts}") + @classmethod + def _click_InputDialog(cls, set_int: Optional[int] = None): + """Needs to be queued with QTimer.singleShot before triggering the message box""" + for widget in cls.app.topLevelWidgets(): + if isinstance(widget, QInputDialog) and widget.isVisible(): + if set_int: + widget.setIntValue(set_int) + QTest.qWait(SHORT_DELAY) + widget.accept() + def _close_welcome(self): self.main_window.welcome_window.view.close() diff --git a/mantidimaging/gui/test/test_gui_system_reconstruction.py b/mantidimaging/gui/test/test_gui_system_reconstruction.py new file mode 100644 index 00000000000..80380299d45 --- /dev/null +++ b/mantidimaging/gui/test/test_gui_system_reconstruction.py @@ -0,0 +1,86 @@ +# Copyright (C) 2021 ISIS Rutherford Appleton Laboratory UKRI +# SPDX - License - Identifier: GPL-3.0-or-later + +import pytest + +from PyQt5.QtTest import QTest +from PyQt5.QtCore import Qt, QTimer + +from mantidimaging.gui.test.gui_system_base import GuiSystemBase, SHOW_DELAY, SHORT_DELAY +from mantidimaging.gui.windows.recon.view import ReconstructWindowView +from mantidimaging.gui.dialogs.cor_inspection.view import CORInspectionDialogView + + +class TestGuiSystemReconstruction(GuiSystemBase): + def setUp(self) -> None: + super().setUp() + self._close_welcome() + self._load_data_set() + + self._open_reconstruction() + self.assertIsNotNone(self.main_window.recon) + assert isinstance(self.main_window.recon, ReconstructWindowView) # for yapf + self.assertTrue(self.main_window.recon.isVisible()) + self.recon_window = self.main_window.recon + + def tearDown(self) -> None: + self.recon_window.close() + assert isinstance(self.main_window.recon, ReconstructWindowView) + self.assertFalse(self.main_window.recon.isVisible()) + self._close_stack_tabs() + super().tearDown() + self.assertFalse(self.main_window.isVisible()) + + def test_correlate(self): + for _ in range(5): + QTest.mouseClick(self.recon_window.correlateBtn, Qt.MouseButton.LeftButton) + + QTest.qWait(SHORT_DELAY) + self._wait_until(lambda: self.recon_window.correlateBtn.isEnabled()) + + def test_minimise(self): + for i in range(2, 6): + QTimer.singleShot(SHORT_DELAY, lambda: self._click_InputDialog(set_int=i)) + QTest.mouseClick(self.recon_window.minimiseBtn, Qt.MouseButton.LeftButton) + + QTest.qWait(SHORT_DELAY) + self._wait_until(lambda: self.recon_window.minimiseBtn.isEnabled(), max_retry=200) + QTest.qWait(SHORT_DELAY) + + @classmethod + def _click_cor_inspect(cls): + cls._wait_for_widget_visible(CORInspectionDialogView) + for widget in cls.app.topLevelWidgets(): + if isinstance(widget, CORInspectionDialogView): + QTest.qWait(SHORT_DELAY) + QTest.mouseClick(widget.finishButton, Qt.MouseButton.LeftButton) + + def test_refine(self): + QTimer.singleShot(SHORT_DELAY, lambda: self._click_InputDialog(set_int=4)) + QTest.mouseClick(self.recon_window.minimiseBtn, Qt.MouseButton.LeftButton) + self._wait_until(lambda: self.recon_window.minimiseBtn.isEnabled(), max_retry=200) + + for _ in range(5): + QTimer.singleShot(SHORT_DELAY, lambda: self._click_cor_inspect()) + QTest.mouseClick(self.recon_window.refineCorBtn, Qt.MouseButton.LeftButton) + QTest.qWait(SHORT_DELAY * 2) + + QTest.qWait(SHOW_DELAY) + + @pytest.mark.skip(reason="Triggers #1110") + def test_refine_stress(self): + for i in range(20): + print(f"test_refine_stress iteration {i}") + QTest.mouseClick(self.recon_window.correlateBtn, Qt.MouseButton.LeftButton) + QTest.qWait(SHORT_DELAY) + self._wait_until(lambda: self.recon_window.correlateBtn.isEnabled()) + + QTimer.singleShot(SHORT_DELAY, lambda: self._click_InputDialog(set_int=3)) + QTest.mouseClick(self.recon_window.minimiseBtn, Qt.MouseButton.LeftButton) + self._wait_until(lambda: self.recon_window.minimiseBtn.isEnabled(), max_retry=200) + + QTimer.singleShot(SHORT_DELAY, lambda: self._click_cor_inspect()) + QTest.mouseClick(self.recon_window.refineCorBtn, Qt.MouseButton.LeftButton) + QTest.qWait(SHORT_DELAY * 2) + + QTest.qWait(SHOW_DELAY)