Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
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 notifications@github.comwrote:
|
|
@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? |
jreback
and 2 others
commented on an outdated diff
Jun 17, 2013
| @@ -35,7 +38,7 @@ | ||
| N = 30 | ||
| K = 4 | ||
| - | ||
| +_FORCE_NETWORK_ERROR = False |
jtratner
Contributor
|
|
@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 notifications@github.com wrote:
|
|
I believe this is all rebased now, I'll work on adding this to the wiki page. |
|
@jreback hey, this has actually been working for a while haha. (rebased it about 10 minutes after you merged haha). @gliptak if you have a moment - could you take a look at this and see whether any of the functions could either:
Thanks! |
|
@jtratner thanks for completing the changes. your code certainly makes these |
|
@cpcloud well, we should profile some of these and if we find certain ones On Wed, Jun 19, 2013 at 9:19 PM, gliptak notifications@github.com wrote:
|
|
i think it was |
|
nose generator opinion looks good |
|
maybe note that tests taking more than 0.5 seconds should be marked as slow...if u agree with that. |
|
@cpcloud I have no opinion on it. Also, should I edit the release notes for this too? I just edited RELEASE.rst, not the specific v0.11.1 file |
|
u can do that, although that the content of that file will soon be moved to |
|
Not a big deal to me. In fact, if I get on the wrong side of the On Wed, Jun 19, 2013 at 9:43 PM, Phillip Cloud notifications@github.comwrote:
|
|
sounds like a plan |
jtratner
referenced
this pull request
Jun 20, 2013
Closed
pandas.io.tests.test_google:TestGoogle.test_get_data hangs during local testing #3916
|
@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 |
cpcloud
referenced
this pull request
Jun 20, 2013
Closed
TST: Make network decorator impose a skipTest catching URLErrors #3910
|
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 |
cpcloud
commented on the diff
Jun 20, 2013
| + The decorated test ``t``, with checks for connectivity errors. | ||
| + | ||
| + Example | ||
| + ------- | ||
| + | ||
| + In this example, you see how it will raise the error if it can connect to | ||
| + the url:: | ||
| + >>> @with_connectivity_check("http://www.yahoo.com") | ||
| + ... def test_something_with_yahoo(): | ||
| + ... raise IOError("Failure Message") | ||
| + >>> test_something_with_yahoo() | ||
| + Traceback (most recent call last): | ||
| + ... | ||
| + IOError: Failure Message | ||
| + | ||
| + I you set check_before_test, it will check the url first and not run the test on failure:: |
|
|
cpcloud
commented on an outdated diff
Jun 20, 2013
| -def network(t): | ||
| +@optional_args | ||
| +def network(t, raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT, | ||
| + error_classes=(IOError,)): |
cpcloud
Member
|
|
looks ok 2 me ... @jreback ? |
|
yep go ahead and merge |
|
in new release notes format ? |
|
it is |
|
oh but slight error |
cpcloud
commented on an outdated diff
Jun 20, 2013
| @@ -91,6 +91,11 @@ pandas 0.11.1 | ||
| integers or floats that are in an epoch unit of ``s, ms, us, ns`` | ||
| (e.g. unix timestamps or epoch ``s``, with fracional seconds allowed) (:issue:`3540`) | ||
| - DataFrame corr method (spearman) is now cythonized. | ||
| + - Improved ``network`` test decorator to catch ``IOError`` (and therefore | ||
| + ``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`) |
|
|
cpcloud
and 1 other
commented on an outdated diff
Jun 20, 2013
| @@ -386,6 +386,11 @@ Bug Fixes | ||
| - ``read_html`` now correctly skips tests (:issue:`3741`) | ||
| - Fixed a bug where ``DataFrame.replace`` with a compiled regular expression | ||
| in the ``to_replace`` argument wasn't working (:issue:`3907`) | ||
| + - Improved ``network`` test decorator to catch ``IOError`` (and therefore | ||
| + ``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`) |
jtratner
Contributor
|
gliptak
referenced
this pull request
Jun 20, 2013
Merged
Change Finance Options signatures and deprecate year/month parameters #3822
jtratner
added some commits
Jun 15, 2013
|
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.
|
jreback
added a commit
that referenced
this pull request
Jun 21, 2013
|
|
jreback |
36c1263
|
jreback
merged commit 36c1263
into pandas-dev:master
Jun 21, 2013
|
boom! thanks a lot |
jtratner commentedJun 15, 2013
Instead,
networkdecorator in pandas.util.testing catchesIOErrorinstead.You have to opt into failing on tests by setting
pandas.util.testing._RAISE_NETWORK_ERROR_DEFAULTtoTrue.Also adds a
with_network_connectivity_checkthat 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.