Skip to content

BLD/TST: catch more spurious errors in @network decorator #6151

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
2 commits merged into from Jan 28, 2014
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
7 changes: 3 additions & 4 deletions pandas/io/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,9 @@ def test_read_famafrench(self):
class TestFred(tm.TestCase):
@network
def test_fred(self):
"""
Throws an exception when DataReader can't get a 200 response from
FRED.
"""

# Throws an exception when DataReader can't get a 200 response from
# FRED.

start = datetime(2010, 1, 1)
end = datetime(2013, 1, 27)
Expand Down
22 changes: 19 additions & 3 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,17 @@ def dec(f):
return wrapper


_network_error_classes = IOError, httplib.HTTPException
_network_errno_vals = (
101, # Network is unreachable
110, # Connection timed out
104, # Connection reset Error
54, # Connection reset by peer
)

_network_error_classes = (IOError, httplib.HTTPException)

if sys.version_info[:2] >= (3,3):
_network_error_classes += (TimeoutError,)

def can_connect(url, error_classes=_network_error_classes):
"""Try to connect to the given url. True if succeeds, False if IOError
Expand Down Expand Up @@ -998,7 +1007,9 @@ def can_connect(url, error_classes=_network_error_classes):
@optional_args
def network(t, url="http://www.google.com",
raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
check_before_test=False, error_classes=_network_error_classes):
check_before_test=False,
error_classes=_network_error_classes,
skip_errnos=_network_errno_vals):
"""
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 @@ -1084,7 +1095,12 @@ def wrapper(*args, **kwargs):
raise SkipTest
try:
return t(*args, **kwargs)
except error_classes as e:
except Exception as e:
errno = getattr(e,'errno',None)

if not isinstance(e, error_classes) and not errno in skip_errnos:
raise

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