From 1e58489b0dab904af62cfb9d79d6da05e38cb5ab Mon Sep 17 00:00:00 2001 From: y-p Date: Wed, 29 Jan 2014 19:20:20 +0200 Subject: [PATCH 1/2] BLD/TST: @network, SkipTest on certain exception messages, when no errno set --- pandas/util/testing.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 49361501c5975..f9acb94602a92 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -967,7 +967,13 @@ def dec(f): return wrapper +# skip tests on exceptions with this message +_network_error_messages = ( + 'urlopen error timed out', + 'timeout: timed out' + ) +# or this e.errno/e.reason.errno _network_errno_vals = ( 101, # Network is unreachable 110, # Connection timed out @@ -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): @@ -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. @@ -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: From a490ad4f80a4e17f42b138e77cff93c109f32f93 Mon Sep 17 00:00:00 2001 From: y-p Date: Wed, 29 Jan 2014 19:25:11 +0200 Subject: [PATCH 2/2] TST: set default socket timeout to 5 sec in pandas.io.tests SetUp() --- pandas/io/tests/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/io/tests/__init__.py b/pandas/io/tests/__init__.py index e69de29bb2d1d..e6089154cd5e5 100644 --- a/pandas/io/tests/__init__.py +++ b/pandas/io/tests/__init__.py @@ -0,0 +1,4 @@ + +def setUp(): + import socket + socket.setdefaulttimeout(5)