-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
TST: Move explicit connectivity checks to decorator. #3914
Conversation
This version (jtratner/pandas@77ede4b) uses google.com as a proxy for network connectivity like the tests were previously doing. |
@jtratner is there a assert raises warning function? i thought i remember u saying something about it somewhere... |
nvm i added one from here. |
This is what I had before...just be aware that warnings seem kinda finicky (and you might want to remove the @contextmanager
def assert_produces_warning(expected_warning=Warning, filter_level="always"):
"""
Context manager for running code that expects to raise (or not raise)
warnings. Checks that code raises the expected warning and only the
expected warning. Pass ``False`` or ``None`` to check that it does *not*
raise a warning. Defaults to ``exception.Warning``, baseclass of all
Warnings. (basically a wrapper around ``warnings.catch_warnings``).
>>> import warnings
>>> with assert_produces_warning():
... warnings.warn(UserWarning())
...
>>> with assert_produces_warning(False):
... warnings.warn(RuntimeWarning())
...
Traceback (most recent call last):
...
AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
>>> with assert_produces_warning(UserWarning):
... warnings.warn(RuntimeWarning())
Traceback (most recent call last):
...
AssertionError: Did not see expected warning of class 'UserWarning'.
..warn:: This is *not* thread-safe.
"""
with warnings.catch_warnings(record=True) as w:
saw_warning = False
warnings.simplefilter(filter_level)
yield w
extra_warnings = []
for actual_warning in w:
if expected_warning and \
issubclass(actual_warning.category, expected_warning):
saw_warning = True
else:
extra_warnings.append(actual_warning.category.__name__)
if expected_warning:
assert saw_warning, ("Did not see expected warning of class %r."
% expected_warning.__name__)
assert not extra_warnings, ("Caused unexpected warning(s): %r."
% extra_warnings) |
i aspire to document like u |
haha :) Easy to test the basics when you put it into a doctest... On Sat, Jun 15, 2013 at 1:44 PM, Phillip Cloud [email protected]:
|
@cpcloud if you use it, nice to stick it in util/testing so it can be used elsewhere. |
yep sure thing |
oh i c u r referring to these doctests |
this would be nice 2 merge i think this might address the hanging of google testing and some of those annoying network errors that have been sporadically popping up on travis. @jreback anything to add? |
@@ -35,7 +38,7 @@ | |||
|
|||
N = 30 | |||
K = 4 | |||
|
|||
_FORCE_NETWORK_ERROR = False |
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 this be done in the decorator itself? (as a parameter?)
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, if you want to do that it's possible... Just have to add another level
of wrapper :P what should the keyword argument be? raise_error?
On Jun 17, 2013 9:47 AM, "jreback" [email protected] wrote:
In pandas/util/testing.py:
@@ -35,7 +38,7 @@
N = 30
K = 4
+_FORCE_NETWORK_ERROR = False
can this be done in the decorator itself? (as a parameter?)
—
Reply to this email directly or view it on GitHubhttps://github.com//pull/3914/files#r4724107
.
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.
probably raise_on_error
like the rest of pandas :)
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.
raise_on_error=False
would be my recommend, so a 'normal' network error will invoke a skip test,otherwise raise (and if you are actually testing the network connectivity code, you can make this 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.
Don't merge this quite yet - pushed an extra commit to see if I could get
at the error this and @cpcloud 's build hit... But then it passed :-/
@jreback @cpcloud Okay, I added optional I hooked A few points:
|
@jtratner need to rebase 1 more time as we just merged stuff (just release notes conflict)... otherwise ready 2 go? |
@jreback I'll do it after work - need to remove a test snippet I added to try to get at a weird build failure - check out this build - https://travis-ci.org/jtratner/pandas/builds/8187252 - @cpcloud had the same error on a recent build too, so it's not the decorator (and wouldn't be caught by the decorator anyways). I'm puzzled by what set of circumstances causes that test to fail in that way. |
I think that error might be that you have a 0-len series, which you are then indexing... (e.g. the call failed but it didn't raise, rather returned something)
|
@jreback are you okay with the connectivity decorator? Don't want to add unnecessary complexity, but I think it's useful. |
@jtratner the connectivity check is fine |
Yes on your question @jreback
|
need rebase (prob release notes conflict) |
@jtratner as an aside this is something that would like to show how to use in a testing page |
yes test examples would be nice |
@jtratner no that's what I meant what we need is something that says here is the toolbox for testing eg catch warnings - use this almost like a style guide |
Okay, I can do that. I'm in the midst of adding all the Exception tests On Tue, Jun 18, 2013 at 9:45 PM, jreback [email protected] wrote:
|
I believe this is all rebased now, I'll work on adding this to the wiki page. |
@jtratner can u rebase? i'll run |
@cpcloud on other note...let's just try to close out 0.11.1......I am going to stop moving things in...... |
very much agreed 👍 |
still need to rebase though :) gh is warning about merge conflicts |
this is now mergeable. If you commimt is, it will close the other issue too. Also, @cpcloud I'd prefer to merge this, then go ahead and try to figure out the |
... | ||
IOError: Failure Message | ||
|
||
I you set check_before_test, it will check the url first and not run the test on failure:: |
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.
small typo...
looks ok 2 me ... @jreback ? |
yep go ahead and merge |
in new release notes format ? |
it is |
oh but slight error |
``URLError`` as well). Added ``with_connectivity_check`` decorator to allow | ||
explicitly checking a website as a proxy for seeing if there is network | ||
connectivity. Plus, new ``optional_args`` decorator factory for decorators. | ||
(:issue:`GH3910`, :issue:`GH3914`) |
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.
just write the issue # here, no need to write "GH"
TST: Enforce more strict rules about ignoring IOErrors with network tests ENH: Allow keyword arguments to network decorator ENH: skip try/except checks if raise_on_error
Instead, network decorator in pandas.util.testing checks for that instead. You have to opt into failing on tests by setting `pandas.util.testing._FORCE_NETWORK_ERROR` to `True`. CLN: Move imports and test skip to top of file
Allows tests to check that a url is available before bubbling up an error from a test case. TST: Change tests to use with_connectivity_check to better approximate previous behavior TST: Add check_before_test option to with_connectivity_check. CLN: PEP8 all the recent jratner code
finally pushed it -- sorry bout that. with the new doc format...it's even able to rebase automatically which is great! |
EPIC WIN! |
haha :) |
so.... @jtratner ready to go? |
Yep.
|
TST: Move explicit connectivity checks to decorator.
boom! thanks a lot |
Instead,
network
decorator in pandas.util.testing catchesIOError
instead.You have to opt into failing on tests by setting
pandas.util.testing._RAISE_NETWORK_ERROR_DEFAULT
toTrue
.Also adds a
with_network_connectivity_check
that can automatically check for a connection.Fixes #3910.
This version of the fix ignores all IOErrors and assumes there are connectivity problems
with any URLError.