Skip to content

Commit

Permalink
Add test_run_operation_stack test for most operations
Browse files Browse the repository at this point in the history
Add a system gui test to run each operations (excluding those that
operate on sinograms).

test_run_operation_stack_safe is skipped for now, as it requires more
work on error handling that should wait until after release.
  • Loading branch information
samtygier-stfc committed Aug 20, 2021
1 parent 7de2e79 commit 37b20e6
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- name: GUI Tests System
shell: bash -l {0}
run: |
xvfb-run --auto-servernum python -m pytest -rs -p no:xdist -p no:randomly -p no:repeat -p no:cov --run-system-tests
xvfb-run --auto-servernum python -m pytest -vs -rs -p no:xdist -p no:randomly -p no:repeat -p no:cov --run-system-tests
timeout-minutes: 15

- name: GUI Tests Applitools
Expand All @@ -86,7 +86,7 @@ jobs:
APPLITOOLS_BATCH_ID: ${{ github.sha }}
GITHUB_BRANCH_NAME: ${{ github.head_ref }}
run: |
xvfb-run --auto-servernum python -m pytest -rs -p no:xdist -p no:randomly -p no:repeat -p no:cov mantidimaging/eyes_tests
xvfb-run --auto-servernum python -m pytest -vs -rs -p no:xdist -p no:randomly -p no:repeat -p no:cov mantidimaging/eyes_tests
timeout-minutes: 15

- name: Coveralls
Expand Down
2 changes: 1 addition & 1 deletion mantidimaging/gui/test/gui_system_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def tearDown(self) -> None:
def _click_messageBox(cls, button_text: str):
"""Needs to be queued with QTimer.singleShot before triggering the message box"""
for widget in cls.app.topLevelWidgets():
if isinstance(widget, QMessageBox):
if isinstance(widget, QMessageBox) and widget.isVisible():
for button in widget.buttons():
if button.text().replace("&", "") == button_text:
QTest.mouseClick(button, Qt.LeftButton)
Expand Down
125 changes: 125 additions & 0 deletions mantidimaging/gui/test/test_gui_system_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Copyright (C) 2021 ISIS Rutherford Appleton Laboratory UKRI
# SPDX - License - Identifier: GPL-3.0-or-later

from itertools import product

import pytest
from parameterized import parameterized
from PyQt5.QtTest import QTest
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QFormLayout, QLabel, QWidget

from mantidimaging.gui.test.gui_system_base import GuiSystemBase, SHOW_DELAY, LOAD_DELAY
from mantidimaging.gui.windows.stack_choice.view import StackChoiceView
from mantidimaging.gui.windows.operations.view import FiltersWindowView

OP_LIST = [
("Arithmetic", [["Multiply", "2"]]),
("Circular Mask", []),
("Clip Values", [["Clip Max", "10000"]]),
("Crop Coordinates", [["ROI", "10,10,100,100"]]),
("Divide", []),
("Flat-fielding", []),
("Gaussian", []),
("Median", []),
# ("Monitor Normalisation", []),
("NaN Removal", []),
("Remove Outliers", []),
("Rebin", []),
# ("Remove all stripes", []),
# ("Remove dead stripes", []),
# ("Remove large stripes", []),
# ("Stripe Removal", []),
# ("Remove stripes with filtering", []),
# ("Remove stripes with sorting and fitting", []),
("Rescale", [["Max input", "10000"]]),
("Ring Removal", []),
("ROI Normalisation", []),
("Rotate Stack", []),
]


class TestGuiSystemLoading(GuiSystemBase):
def setUp(self) -> None:
super().setUp()
self._close_welcome()
self._load_data_set()

self._open_operations()
self.assertIsNotNone(self.main_window.filters)
assert isinstance(self.main_window.filters, FiltersWindowView) # for yapf
self.assertTrue(self.main_window.filters.isVisible())
self.op_window = self.main_window.filters

@staticmethod
def _get_operation_parameter_widget(form: QFormLayout, param_name: str) -> QWidget:
for i in range(form.rowCount()):
label_item = form.itemAt(i * 2)
widget_item = form.itemAt(i * 2 + 1)

if label_item is not None and widget_item is not None:
label = label_item.widget()
assert isinstance(label, QLabel)
if label.text() == param_name:
return widget_item.widget()

raise ValueError(f"Could not find '{param_name}' in form")

@classmethod
def _click_stack_selector(cls, keep_new: bool):
for widget in cls.app.topLevelWidgets():
if isinstance(widget, StackChoiceView):
if keep_new:
QTest.mouseClick(widget.newDataButton, Qt.MouseButton.LeftButton)
else:
QTest.mouseClick(widget.originalDataButton, Qt.MouseButton.LeftButton)

@parameterized.expand(OP_LIST)
def test_run_operation_stack(self, op_name, params):

QTest.qWait(SHOW_DELAY)
index = self.op_window.filterSelector.findText(op_name)
self.assertGreaterEqual(index, 0, f'Operation "{op_name}" not found in filterSelector')
self.op_window.filterSelector.setCurrentIndex(index)
QTest.qWait(SHOW_DELAY)

for param_name, param_value in params:
widget = self._get_operation_parameter_widget(self.op_window.filterPropertiesLayout, param_name)
widget.selectAll()
QTest.keyClicks(widget, param_value)
QTest.keyClick(widget, Qt.Key_Return)
QTest.qWait(SHOW_DELAY)

self.op_window.safeApply.setChecked(False)
QTest.mouseClick(self.op_window.applyButton, Qt.MouseButton.LeftButton)
QTest.qWait(SHOW_DELAY + 5000)

self.main_window.filters.close()
QTest.qWait(SHOW_DELAY)

@parameterized.expand(product(OP_LIST, ["new", "original"]))
@pytest.mark.skip() # needs investigation
def test_run_operation_stack_safe(self, op_info, keep_stack):
op_name, params = op_info
print(f"test_run_operation_stack_safe {op_name=} {params=} {keep_stack=}")
QTest.qWait(SHOW_DELAY)
index = self.op_window.filterSelector.findText(op_name)
self.assertGreaterEqual(index, 0, f'Operation "{op_name}" not found in filterSelector')
self.op_window.filterSelector.setCurrentIndex(index)
QTest.qWait(SHOW_DELAY)

for param_name, param_value in params:
widget = self._get_operation_parameter_widget(self.op_window.filterPropertiesLayout, param_name)
widget.selectAll()
QTest.keyClicks(widget, param_value)
QTest.keyClick(widget, Qt.Key_Return)
QTest.qWait(SHOW_DELAY)

self.op_window.safeApply.setChecked(True)
QTimer.singleShot(LOAD_DELAY, lambda: self._click_stack_selector(keep_stack == "new"))
QTest.mouseClick(self.op_window.applyButton, Qt.MouseButton.LeftButton)

QTest.qWait(LOAD_DELAY + 1000)

self.main_window.filters.close()
QTest.qWait(SHOW_DELAY)

0 comments on commit 37b20e6

Please sign in to comment.