Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/io/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

def setUp():
import socket
socket.setdefaulttimeout(5)
20 changes: 19 additions & 1 deletion pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,13 @@ def dec(f):

return wrapper

# skip tests on exceptions with this message
_network_error_messages = (
'urlopen error timed out',
Copy link
Contributor

Choose a reason for hiding this comment

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

nice way to hack around this :)

Copy link
Author

Choose a reason for hiding this comment

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

desperate you mean. I can't believe how screwed up this corner of python is,
you literraly have to do all this to catch these network errors. Timeouts can bubble
up in at least 5 different ways, diff exceptions, with errno or with out. nightmare.

The code for @network, and the kwarg lists were really nice to see after
wallowing in the muck of indexing.py. kudos.

'timeout: timed out'
)

# or this e.errno/e.reason.errno
_network_errno_vals = (
101, # Network is unreachable
110, # Connection timed out
Expand All @@ -976,6 +982,12 @@ def dec(f):
60, # urllib.error.URLError: [Errno 60] Connection timed out
)

# Both of the above shouldn't mask reasl issues such as 404's
# or refused connections (changed DNS).
# But some tests (test_data yahoo) contact incredibly flakey
# servers.

# and conditionally raise on these exception types
_network_error_classes = (IOError, httplib.HTTPException)

if sys.version_info[:2] >= (3,3):
Expand Down Expand Up @@ -1010,7 +1022,9 @@ def network(t, url="http://www.google.com",
raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
check_before_test=False,
error_classes=_network_error_classes,
skip_errnos=_network_errno_vals):
skip_errnos=_network_errno_vals,
_skip_on_messages=_network_error_messages,
):
"""
Label a test as requiring network connection and, if an error is
encountered, only raise if it does not find a network connection.
Expand Down Expand Up @@ -1108,6 +1122,10 @@ def wrapper(*args, **kwargs):
raise SkipTest("Skipping test due to known errno"
" and error %s" % e)

if any([m.lower() in str(e).lower() for m in _skip_on_messages]):
raise SkipTest("Skipping test because exception message is known"
" and error %s" % e)

if raise_on_error or can_connect(url, error_classes):
raise
else:
Expand Down