-
Notifications
You must be signed in to change notification settings - Fork 104
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
Handle unexpected return value #2157
Conversation
I think I'll include a test for this case before review... |
Yes, this part of ERT is very poorly tested. There are numerous examples of qt testing, however, so setup should be fairly copy-paste. |
a530705
to
bd6e5b1
Compare
bd6e5b1
to
05b3cc8
Compare
The application-code uses static methods from Qt to display modal windows. The proposed test applies a delayed timer and relies on the application-instance to provide a hook for the window in order to close it programmatically. Note that the modal dialogs must not use native widgets in the test because closing these crashes Python. We assume that these methods return the same values for native and Qt-based widgets. |
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.
The application-code uses static methods from Qt to display modal windows. The proposed test applies a delayed timer and relies on the application-instance to provide a hook for the window in order to close it programmatically.
Did you take a look at the other QT tests? You're not supposed to instantiate QApplication
directly because it will probably not work as intended: https://pytest-qt.readthedocs.io/en/latest/qapplication.html
If you're simply testing some dialogs, use qtbot
as we do elsewhere.
Good point - will check out the exit-issue mentioned here.
IMO it's not obvious how A completely different approach is to parse the |
05b3cc8
to
056fbc0
Compare
Hmm... when phrasing the goal of the test and the quoted question, I realize that adding static typing achieves the same goal. The missing piece is to set up mypy to include ert_gui in the analysis. Please consider this approach instead.... |
No, we add a test. Here it is: from qtpy.QtWidgets import QFileDialog
from ert_gui.ertwidgets.pathchooser import PathChooser
from ert_gui.ertwidgets.models.path_model import PathModel
def test_selectfile(qtbot, tmpdir, monkeypatch):
model = PathModel(tmpdir, must_be_a_file=True)
widget = PathChooser(model)
qtbot.addWidget(widget)
monkeypatch.setattr(QFileDialog, "getOpenFileName", lambda *args: ("foo", "bar"))
with qtbot.waitActive(widget):
widget.show()
widget.selectPath() |
056fbc0
to
797c45b
Compare
Change with qtbot.waitActive(widget):
widget.show() to something like widget.show()
qbot.add_widget(widget)
qtbot.waitForWindowShown(widget)
…
asserts Activation requires a window manager, but we don't need that here. So my bad! |
797c45b
to
4a1a0ba
Compare
4a1a0ba
to
23c719c
Compare
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.
Super! Thanks
Issue
Resolves #2004
Approach
Handle the unexpected return-value properly