Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added success message to run modes, removed useless param, used mocks instead of test specific params #571

Merged
merged 12 commits into from
Nov 15, 2024

Conversation

sebastian-swob
Copy link
Collaborator

No description provided.

removed useless param,
used mocks instead of test specific params
@sebastian-swob sebastian-swob requested review from zuckerruebe and ahobeost and removed request for zuckerruebe November 13, 2024 11:40
This was linked to issues Nov 13, 2024
mainWindow.editor.trnsysObj, stw.StorageTank
)
configureStorageDialog = self.storageTank.mouseDoubleClickEvent(
_core.QEvent.MouseButtonDblClick, isTest=True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice choice. Dealing with the dialog directly keeps this GUI part out of these tests. When we start separating the GUI code properly, these tests should stay valid and the "doubleclickeEvent" would be a minimal GUI test (not for now).

@@ -57,6 +57,11 @@ def runModes(project: prj.CreateOrLoadProject, mainWindow: mw.MainWindow): # ty
informativeText=constants.ERROR_RUNNING_MODES_TRNSYS_ADDITIONAL,
buttons=[_qtw.QMessageBox.Ok],
)
else:
MessageBox.create(
messageText=f"{constants.SUCCESS_RUNNING_MODES}{','.join(failures)}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

def mouseDoubleClickEvent(
self, event: _qtw.QGraphicsSceneMouseEvent, isTest=False
) -> (_tp.Optional)[ConfigureStorageDialog]:
def mouseDoubleClickEvent(self, event: _qtw.QGraphicsSceneMouseEvent):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better this way, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add return type, too. (-> None, I guess?)

@@ -1,11 +1,13 @@
import pathlib as _pl

import PyQt5.QtCore as _core
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All imports in pytrnsys/trnsysGUI should be of the form import foo.bar.baz as _alias. In particular, in new code, we don't import individual classes.

def triggerStorageDialog(
self, qtbot, monkeypatch
) -> ConfigureStorageDialog:
monkeypatch.setattr(QMessageBox, "exec", lambda self: QMessageBox.Ok)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we maybe patch QMessageBox.information or (warning, or whichever is appropriate, directly?). Might require small changes in productive code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zuckerruebe.

Not sure if that would work.
The main issue is that pytest grinds to a halt until the dialog is closed.
Thus, the problem to solve is:
ensuring that exec() is passed cleanly during testing.

Does the current patch seem better with this information, or would you still prefer patching something else to reach the same goal?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, I think a bigger overhaul of this is in order.
Two architectural choices would be helpful here.
1: The current state should be saved in memory, so that the entire state can be reproduced at the end of the export.
2: MVP or MVVM, so we do not have to deal with the GUI part at all in these tests.

This would not be part of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't know why I get e-mails regarding this pull request. But because I do, I felt I'd chirp in. But I don't have a strong opinion nor a lot of context.

If it's possible to use, e.g., QMessageBox.information, then, if you monkeypatch that one .exec will never get called because it's called within information.

hxInput = "90"
hxOutput = "50"
hxName = "Test hx"
errors = []

configureStorageDialog = self.triggerStorageDialog(qtbot)
configureStorageDialog = triggerStorageDialog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triggerStorageDialog is a very confusing name. Just name the parameter configureStorageDialog directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastian-swob: I took care of this.

@@ -60,11 +64,11 @@ def testAddHxSuccess(self, qtbot):
if errors:
raise ExceptionGroup(f"Found {len(errors)} issues.", errors)

def testAddHxMissingNameFailure(self, qtbot):
def testAddHxMissingNameFailure(self, triggerStorageDialog):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito.

@@ -75,11 +79,11 @@ def testAddHxMissingNameFailure(self, qtbot):
== configureStorageDialog.MISSING_NAME_ERROR_MESSAGE
)

def testAddHxInvalidRangeFailure(self, qtbot):
def testAddHxInvalidRangeFailure(self, triggerStorageDialog):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito.

@@ -101,23 +105,23 @@ def testRemoveHxSuccess(self, qtbot):

assert len(self.storageTank.heatExchangers) == 0

def testAddPortPairSuccess(self, qtbot):
def testAddPortPairSuccess(self, triggerStorageDialog):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito.

configureStorageDialog.manPortLeI.setText(portPairInput)
configureStorageDialog.manPortLeO.setText(portPairOutput)
configureStorageDialog.manlButton.setChecked(True)
configureStorageDialog.addPortPair()

assert len(self.storageTank.directPortPairs) == 2

def testAddPortPairHeightFailure(self, qtbot):
def testAddPortPairHeightFailure(self, triggerStorageDialog):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito.

@@ -128,11 +132,11 @@ def testAddPortPairHeightFailure(self, qtbot):
== configureStorageDialog.PORT_HEIGHT_ERROR_MESSAGE
)

def testAddPortPairNoSideSelectedFailure(self, qtbot):
def testAddPortPairNoSideSelectedFailure(self, triggerStorageDialog):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito.

@@ -143,8 +147,8 @@ def testAddPortPairNoSideSelectedFailure(self, qtbot):
== configureStorageDialog.NO_SIDE_SELECTED_ERROR_MESSAGE
)

def testRemovePortPairSuccess(self, qtbot):
configureStorageDialog = self.triggerStorageDialog(qtbot)
def testRemovePortPairSuccess(self, triggerStorageDialog):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito.

def mouseDoubleClickEvent(
self, event: _qtw.QGraphicsSceneMouseEvent, isTest=False
) -> (_tp.Optional)[ConfigureStorageDialog]:
def mouseDoubleClickEvent(self, event: _qtw.QGraphicsSceneMouseEvent):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add return type, too. (-> None, I guess?)

@ahobeost ahobeost linked an issue Nov 14, 2024 that may be closed by this pull request
Copy link

sonarcloud bot commented Nov 14, 2024

@ahobeost
Copy link
Contributor

@sebastian-swob and @zuckerruebe:
Please have another look.

I have resolved the issue with the tempering valves as well.

Explanation:
if isTempering == True
This is turned off, so the regimes can do their thing.
At the end, it is turned back on (for all such valves), so the User does not have to turn it back on Manually

@ahobeost ahobeost merged commit 1048041 into master Nov 15, 2024
6 checks passed
@ahobeost ahobeost deleted the tiny-improvements branch November 15, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants