Skip to content

Commit

Permalink
integration tests now expect workflows to finish with qmessagebox.inf…
Browse files Browse the repository at this point in the history
…ormation
  • Loading branch information
walshmm committed Oct 24, 2024
1 parent fec92ca commit eeffd7c
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions tests/integration/test_workflow_panels_happy_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ def _setup_gui(self, qapp):
self._warningMessageBox = mock.patch(
"qtpy.QtWidgets.QMessageBox.warning",
lambda *args, **kwargs: pytest.fail(
"WARNING messagebox:\n" + f" args: {args}\n" + f" kwargs: {kwargs}", pytrace=False
),
"WARNING This test seems to be missing expected calibration and/or normalization data", pytrace=False
)
if "Reduction is missing calibration data," in args[2]
else pytest.fail("WARNING messagebox:\n" + f" args: {args}\n" + f" kwargs: {kwargs}", pytrace=False),
)
self._warningMessageBox.start()

Expand Down Expand Up @@ -182,10 +184,8 @@ def _setup_gui(self, qapp):

# Automatically continue at the end of each workflow.
self._actionPrompt = mock.patch(
"snapred.ui.presenter.WorkflowPresenter.ActionPrompt.prompt",
lambda *args: TestGUIPanels._actionPromptContinue(
*args, match=r".*The workflow has been completed successfully.*"
),
"qtpy.QtWidgets.QMessageBox.information",
lambda *args: TestGUIPanels._actionPromptContinue(*args, match=r".*has been completed successfully.*"),
)
self._actionPrompt.start()
# ---------------------------------------------------------------------------
Expand All @@ -206,12 +206,12 @@ def _setup_gui(self, qapp):
self.exitStack.close()

@staticmethod
def _actionPromptContinue(title, message, action, parent=None, match=r".*"): # noqa: ARG004
def _actionPromptContinue(parent, title, message, match=r".*"): # noqa: ARG004
_pattern = re.compile(match)
if not _pattern.match(message):
pytest.fail(
f"unexpected: ActionPrompt.prompt('{title}', '{message}'...)\n"
+ f" expecting: ActionPrompt.prompt(...'{message}'...)"
f"unexpected: QMessageBox.information('{title}', '{message}'...)\n"
+ f" expecting: QMessageBox.information(...'{message}'...)"
)

@pytest.mark.skip(reason="each workflow panel now has a separate test")
Expand Down Expand Up @@ -1160,7 +1160,7 @@ def test_normalization_panel_happy_path(self, qtbot, qapp, calibration_home_from

def test_reduction_panel_happy_path(self, qtbot, qapp, reduction_home_from_mirror):
##
## WARNING: this test requires EXISTING diffraction-calibration and normalization-calibration data!
## NOTE: WARNING: this test requires EXISTING diffraction-calibration and normalization-calibration data!
## As an alternative `test_calibration_and_reduction_panels_happy_path`, now skipped, could be run instead.
##

Expand All @@ -1172,6 +1172,20 @@ def test_reduction_panel_happy_path(self, qtbot, qapp, reduction_home_from_mirro
# under the existing location within the mirror.
tmpReductionHomeDirectory = reduction_home_from_mirror(reductionRunNumber) # noqa: F841

self.completionMessageHasAppeared = False

def completionMessageBoxAssert(*args, **kwargs): # noqa: ARG001
self.completionMessageHasAppeared = True
assert "Reduction has completed successfully!" in args[2]
return QMessageBox.Ok

self._actionPrompt.stop()
completionMessageBox = mock.patch(
"qtpy.QtWidgets.QMessageBox.information",
completionMessageBoxAssert, # noqa: ARG005
)
completionMessageBox.start()

with (
qtbot.captureExceptions() as exceptions,
suppress(InterruptWithBlock),
Expand Down Expand Up @@ -1307,25 +1321,20 @@ def test_reduction_panel_happy_path(self, qtbot, qapp, reduction_home_from_mirro
# (2) execute the reduction workflow
with qtbot.waitSignal(actionCompleted, timeout=120000):
qtbot.mouseClick(workflowNodeTabs.currentWidget().continueButton, Qt.MouseButton.LeftButton)
qtbot.waitUntil(lambda: isinstance(workflowNodeTabs.currentWidget().view, ReductionSaveView), timeout=60000)
saveView = workflowNodeTabs.currentWidget().view # noqa: F841

"""
# set "author" and "comment"
saveView.fieldAuthor.setText("kat")
saveView.fieldComments.setText("calibration-panel integration test")
"""

# continue in order to save workspaces and to finish the workflow
with qtbot.waitSignal(actionCompleted, timeout=60000):
qtbot.mouseClick(workflowNodeTabs.currentWidget().continueButton, Qt.MouseButton.LeftButton)

# `ActionPrompt.prompt("..The workflow has completed successfully..)` gives immediate mocked response:
# Here we still need to wait until the ADS cleanup has occurred,
# or else it will happen in the middle of the next workflow. :(
qtbot.waitUntil(
lambda: isinstance(workflowNodeTabs.currentWidget().view, ReductionRequestView), timeout=5000
lambda: self.completionMessageHasAppeared,
timeout=60000,
)
completionMessageBox.stop()

###############################
########### END OF TEST #######
Expand Down

0 comments on commit eeffd7c

Please sign in to comment.