From eeffd7c953344bb463422599dcb44424b55f9508 Mon Sep 17 00:00:00 2001 From: Michael Walsh Date: Thu, 24 Oct 2024 14:50:15 -0400 Subject: [PATCH] integration tests now expect workflows to finish with qmessagebox.information --- .../test_workflow_panels_happy_path.py | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/tests/integration/test_workflow_panels_happy_path.py b/tests/integration/test_workflow_panels_happy_path.py index b2e6bab32..b62128dcd 100644 --- a/tests/integration/test_workflow_panels_happy_path.py +++ b/tests/integration/test_workflow_panels_happy_path.py @@ -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() @@ -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() # --------------------------------------------------------------------------- @@ -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") @@ -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. ## @@ -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), @@ -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 #######