Skip to content

Support for capturing signals and args and improved SignalTimeoutError messages #153

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

Merged
merged 12 commits into from
Sep 16, 2016

Conversation

MShekow
Copy link

@MShekow MShekow commented Aug 12, 2016

waitSignal(): added support for capturing arguments when callback was not satisfied (into blocker.all_args) and improved the message of SignalTimeoutError to include the name of the signal, non-matching signal parameters and name of the callback.

waitSignals(): Added capturing signals and their arguments (see all_signals_and_args). Cleaned up large parts of the code of MultiSignalBlocker for better readability. Improved the message of SignalTimeoutError. Updated documentation. Added tests. See #151

… (into blocker.all_args) and improved the message of SignalTimeoutError to include the name of the signal, non-matching signal parameters and name of the callback. Next step is to include similar functionality for MultiSignalBlocker.
…ee all_signals_and_args). Cleaned up large parts of the code of MultiSignalBlocker for better readability. Updated documentation. Added tests. #151
@coveralls
Copy link

coveralls commented Aug 12, 2016

Coverage Status

Coverage decreased (-2.6%) to 97.354% when pulling 77b1cb0 on MShekow:master into 598c1c2 on pytest-dev:master.

:param Signal signal:
A signal to wait for. Set to ``None`` to just use timeout.
A signal to wait for, or a tuple (signal, signal_name_as_str) to improve the error message that is part
Copy link
Member

Choose a reason for hiding this comment

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

The tuple should be monospaced as well for consistency

@The-Compiler
Copy link
Member

Thanks for your great work on this, looking forward to it!

I added some style comments, and plan to take another closer look when I feel more awake 😆

Some other things to note:

  • The coverage should stay at 100% - can you investigate what's not covered yet?
  • The tests seem to fail with Python 2 and PyQt4/PySide - can you investigate?

@MShekow
Copy link
Author

MShekow commented Aug 12, 2016

Hi. I'm having trouble fixing the bugs. The most problematic issue is unicode strings. Python 2 and 3 seem to work very different (I don't personally care for legacy software, so I never use Python 2). Python 2 breaks my tests because it converts str( ('somestring',) ) to "(u'somestring',)" (i.e. it adds the u which I don't want there.
What I can do is to have a if type(somestring) is unicode check when iterating over the tuple's elements (and convert them with str() in this case), but that only works in Python 2 (Python 3 doesn't recognize unicode). So, what do I do now? Do I really have to do Python version checking in my code to fix this?

@The-Compiler
Copy link
Member

Why don't you want the u'...' there? If a parameter is an unicode string, I'd surely want to see that fact, just like I want to have ' around strings. I'd suggest just adjusting the test accordingly (with a version check probably).

@MShekow
Copy link
Author

MShekow commented Aug 12, 2016

Well, I didn't want the u there due to the tests. I'll follow your suggestion and adapt the tests instead.

@coveralls
Copy link

coveralls commented Aug 12, 2016

Coverage Status

Coverage decreased (-2.5%) to 97.531% when pulling 78ecf73 on MShekow:master into 598c1c2 on pytest-dev:master.

…nts (that we emit in test code as normal strings) are converted to "PyQt4.QtCore.QString(u'<stringcontent>')" by repr(), while as for all other Python 2 builds, this is just "u'<stringcontent>'".
@coveralls
Copy link

coveralls commented Aug 12, 2016

Coverage Status

Coverage decreased (-0.7%) to 99.295% when pulling 061c11d on MShekow:master into 598c1c2 on pytest-dev:master.

@MShekow
Copy link
Author

MShekow commented Aug 12, 2016

So, I've fixed all those things you mentioned and got the tests working again.
Regarding the coverage: I can add tests for those lines the tests do not currently cover. These are (see here for more details: https://coveralls.io/builds/7422331/source?filename=pytestqt%2Fwait_signal.py ):

  1. waitSignals() code that raises TypeError or ValueError when user doesn't provide valid parameters
  2. Line 120: no name for a provided callback could be determined. I'm not sure how to cover that. Maybe callable wrapped inside a functools.partial wrapped inside a functools partial?

Getting emitted signals and arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. versionadded:: 2.1
Copy link
Author

Choose a reason for hiding this comment

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

Is this guess for the next version actually correct?

Copy link
Member

Choose a reason for hiding this comment

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

Yes! 😁

@coveralls
Copy link

coveralls commented Aug 15, 2016

Coverage Status

Coverage decreased (-0.09%) to 99.912% when pulling 6e18d47 on MShekow:master into 598c1c2 on pytest-dev:master.

@coveralls
Copy link

coveralls commented Aug 15, 2016

Coverage Status

Coverage decreased (-0.09%) to 99.912% when pulling 875f941 on MShekow:master into 598c1c2 on pytest-dev:master.

@MShekow
Copy link
Author

MShekow commented Aug 15, 2016

I've done the necessary changes. I don't know how to further increase the coverage, tbh. Please note that coveralls seems to be buggy and the comments aren't always accurate. The actual reduction is by 0.09%. I understand I could get it back to 0% if I had the overriding get_timeout_error_message() functions call their empty super-implementation, but I don't see any good in doing so.

if self._timer is not None:
_silent_disconnect(self._timer.timeout, self._quit_loop_by_timeout)
self._timer.stop()
self._timer = None

def get_timeout_error_message(self):
pass
Copy link
Member

Choose a reason for hiding this comment

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

Since this must be overridden in subclasses, you should do raise NotImplementedError here (docs) - that should also mean no coverage is required for it, and if coverage.py doesn't do so automatically, we can tell it to.

Copy link
Author

Choose a reason for hiding this comment

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

I've changed it in the code, but coveralls still complains about that line not being covered. So, should I use a pragma? I don't see any configuration files in place yet.

@coveralls
Copy link

coveralls commented Aug 15, 2016

Coverage Status

Coverage decreased (-0.09%) to 99.912% when pulling 2316261 on MShekow:master into 598c1c2 on pytest-dev:master.

@nicoddemus
Copy link
Member

I've done the necessary changes. I don't know how to further increase the coverage, tbh.

For this case specifically I would say it is fair to add a # pragma: no cover on that line. 👍

Getting all arguments of non-matching arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. versionadded:: 2.0
Copy link
Member

Choose a reason for hiding this comment

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

This should be 2.1?

@nicoddemus
Copy link
Member

Hey @MShekow, excellent documentation on the tests and code!

Other than adding the comment to skip the missing coverage, my suggestions are just that, suggestions, so feel free to not implement them if you don't really have the time as I'm guessing you have spent quite a few hours on this already.

All your work here is much appreciated!

signal_name = signal_tuple[1]
if not isinstance(signal_name, str) or not signal_name:
raise TypeError("Invalid type for user-provided signal name, "
"expected str but got {}".format(type(signal_name)))
Copy link
Member

Choose a reason for hiding this comment

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

If someone accidentally passed an empty string, they'd get "Invalid type for user-provided signal name, expected str but got str", which might be quite confusing.

Copy link
Author

Choose a reason for hiding this comment

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

You're right. I'll fix this, i.e. split it into two ifs (each one without any or).

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.7%) to 98.326% when pulling 56771f0 on MShekow:master into 598c1c2 on pytest-dev:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.7%) to 98.326% when pulling 56771f0 on MShekow:master into 598c1c2 on pytest-dev:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.7%) to 98.326% when pulling 56771f0 on MShekow:master into 598c1c2 on pytest-dev:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.7%) to 98.326% when pulling 56771f0 on MShekow:master into 598c1c2 on pytest-dev:master.

@coveralls
Copy link

coveralls commented Aug 16, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 56771f0 on MShekow:master into 598c1c2 on pytest-dev:master.

@nicoddemus
Copy link
Member

Hey @MShekow,

Really sorry about the delay on this. Just now I found the time to review it and it looks great! Your entire PR is very well written and your test descriptions are really helpful! 👍

Long overdue, I'm merging this! I plan to have 2.1 out soon real soon. 😁

Also, thanks @The-Compiler for the through review as well. 😉

@nicoddemus nicoddemus merged commit dfbd99d into pytest-dev:master Sep 16, 2016
nicoddemus added a commit to nicoddemus/pytest-qt that referenced this pull request Sep 16, 2016
@MShekow
Copy link
Author

MShekow commented Sep 16, 2016

My pleasure! Thanks for merging :)

nicoddemus added a commit to nicoddemus/pytest-qt that referenced this pull request Oct 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants