-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
removed useless param, used mocks instead of test specific params
mainWindow.editor.trnsysObj, stw.StorageTank | ||
) | ||
configureStorageDialog = self.storageTank.mouseDoubleClickEvent( | ||
_core.QEvent.MouseButtonDblClick, isTest=True |
There was a problem hiding this comment.
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)}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
trnsysGUI/storageTank/widget.py
Outdated
def mouseDoubleClickEvent( | ||
self, event: _qtw.QGraphicsSceneMouseEvent, isTest=False | ||
) -> (_tp.Optional)[ConfigureStorageDialog]: | ||
def mouseDoubleClickEvent(self, event: _qtw.QGraphicsSceneMouseEvent): |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dito.
trnsysGUI/storageTank/widget.py
Outdated
def mouseDoubleClickEvent( | ||
self, event: _qtw.QGraphicsSceneMouseEvent, isTest=False | ||
) -> (_tp.Optional)[ConfigureStorageDialog]: | ||
def mouseDoubleClickEvent(self, event: _qtw.QGraphicsSceneMouseEvent): |
There was a problem hiding this comment.
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?)
Quality Gate passedIssues Measures |
@sebastian-swob and @zuckerruebe: I have resolved the issue with the tempering valves as well. Explanation: |
No description provided.