Skip to content

Commit

Permalink
Add gui system tests for reconstruction
Browse files Browse the repository at this point in the history
Some tests for the tilt/COR interface

test_refine_stress can be used to trigger #1110 so is set to skip.
  • Loading branch information
samtygier-stfc committed Aug 25, 2021
1 parent d8df3cb commit 83318c2
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mantidimaging/gui/test/gui_system_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
86 changes: 86 additions & 0 deletions mantidimaging/gui/test/test_gui_system_reconstruction.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 83318c2

Please sign in to comment.