-
-
Notifications
You must be signed in to change notification settings - Fork 70
Add waitExposed and waitActive methods to QtBot #159
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
Add waitExposed and waitActive methods to QtBot #159
Conversation
2 similar comments
ace332e to
7289785
Compare
|
I plan to release 2.1 after this is merged. |
|
I think we still have some things to consider here, ideally before releasing it as they're API changes - unsorted braindump as I don't have much time right now:
with qtbot.waitForWindowExposed(window):
window.show()
assert window.isVisible()compared to: window.show()
qtbot.waitForWindowExposed(window)
assert window.isVisible() |
|
Good point about I agree having a higher level API is nice, but perhaps we should add them as separate methods rather than changing the original functions? I would rather keep the original Following your example, how about those context managers then: def waitExposed(self, widget, timeout=1000, raising=True):
pass
def waitActive(self, widget, timeout=1000, raising=True):
pass
def waitFocus(self, widget, timeout=1000, raising=True):
passThe last one in particular is tricky to achieve in my experience, specially when executing under Also, I think those high-level APIs are only worthwhile doing for PyQt5... let's move forward only. 😁 |
|
FWIW we already change the function names by stripping the leading I guess adding those would work. No big opinion on backends, I think nobody should use Qt4 nowadays anyways 😆 I also thought about having |
|
OK! Thanks for coming back to this. 😁 I will see if I can tackle this during the week. |
|
Hey @The-Compiler, I implemented After implementing the Consider: widget.show()
assert qtbot.waitForWindowExposed(widget, timeout)vs: with qtbot.waitExposed(widget, timeout):
widget.show()I feel we don't gain much and will bloat the API without compelling reason. What do you think? |
1 similar comment
|
The desire for those two things is actually because I make those mistakes a lot. Accidentally using it as a context manager isn't that bad, accidentally thinking it'd be raising is 😉 The reason I make those mistakes over and over again is because the API is inconsistent - I can use other FWIW, I think the cleanest design/API would be to have convenience wrappers as |
Hmm I see, I agree that those are all valid points. Well, since we are talking about adding two news methods, def waitActive(self, widget, timeout=1000):
"""
Raises a TimeoutError if the widget does not show in timeout miliseconds.
Calls the QTest.qWaitForWindowActive.
PyQt5 only.
"""Similarly for
I agree it is cleaner, but I'm not sure it is better because it is not as convenient to use. Forcing to use Thanks as always for the thoughtful feedback! 😉 |
|
I agree about all your points! I think they definitely should be context managers for consistency, and I agree we can just default to |
193fc3f to
a8e461c
Compare
36c261d to
0dccfcc
Compare
a3bc31f to
5de1611
Compare
1 similar comment
5de1611 to
502c290
Compare
|
@The-Compiler I know you are pretty buys, just a ping to let you know this is ready for reviewing. 😁 |
The-Compiler
left a comment
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.
Some minor stuff, and a SignalTimeout API change which is probably more important 😉
pytestqt/qtbot.py
Outdated
|
|
||
| def waitActive(self, widget, timeout=1000): | ||
| """ | ||
| Context manager that waits for timeout milliseconds or until the window is active. |
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.
Shouldn't the timeout be monospace?
pytestqt/qtbot.py
Outdated
|
|
||
| def waitActive(self, widget, timeout=1000): | ||
| """ | ||
| Context manager that waits for timeout milliseconds or until the window is active. |
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.
Shouldn't the timeout be monospace?
pytestqt/qtbot.py
Outdated
| show_action() | ||
| :param QWidget widget: | ||
| Widget to wait on. |
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.
on -> for?
pytestqt/qtbot.py
Outdated
| Widget to wait on. | ||
| :param int|None timeout: | ||
| How many miliseconds to wait on. |
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.
miliseconds -> milliseconds; on -> for?
|
|
||
| wait_active = waitActive # pep-8 alias | ||
|
|
||
| def waitExposed(self, widget, timeout=1000): |
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.
Same changes as above in this docstring 😉
pytestqt/qtbot.py
Outdated
| .. note:: In Qt5, the actual method called is qWaitForWindowExposed, | ||
| but this name is kept for backward compatibility | ||
| .. note:: In ``PyQt5`` this function is considered deprecated in favor of :meth:`waitForWindowExposed`. |
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.
Should we mention waitExposed instead?
pytestqt/qtbot.py
Outdated
|
|
||
|
|
||
| # provide easy access to SignalTimeoutError to qtbot fixtures | ||
| class TimeoutError(Exception): |
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.
What about inheriting from SignalTimeoutError (for backwards compatibility) and deprecating SignalTimeoutError, like discussed in #157 (comment) some while ago?
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.
Done, well remembered! 😁
| msg = 'widget {} not {} in {} ms.'.format(self._widget, self._adjective_name, self._timeout) | ||
| raise TimeoutError(msg) | ||
| finally: | ||
| self._widget = None |
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.
Is this to avoid leaking memory?
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.
Yes!
|
I implemented all the changes you commented @The-Compiler! |
|
Thanks! 👍 |
Added
waitForWindowExposedfor PyQt5.Fixes #158