From 8f8b71a938dbec2aba002a8a8ed8127976b896cd Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 12 Apr 2012 15:17:25 -0400 Subject: [PATCH 1/3] ENH: @network decorator for tests --- pandas/util/testing.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 9552ed230d051..7a41b32baad0f 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -294,3 +294,40 @@ def skip_if_no_package(*args, **kwargs): package_check(exc_failed_import=SkipTest, exc_failed_check=SkipTest, *args, **kwargs) + +# +# Additional tags decorators for nose +# +def network(t): + """ + Label a test as requiring network connection. + + In some cases it is not possible to assume network presence (e.g. Debian + build hosts). + + Parameters + ---------- + t : callable + The test requiring network connectivity. + + Returns + ------- + t : callable + The decorated test `t`. + + Examples + -------- + A test can be decorated as requiring network like this:: + + from pandas.util.testing import * + + @network + def test_network(self): + print 'Fetch the stars from http://' + + And use ``nosetests -a '!network'`` to exclude running tests requiring + network connectivity. + """ + + t.network = True + return t From 80b9d84b8d213ad827538642c523257bec28412a Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 12 Apr 2012 15:18:15 -0400 Subject: [PATCH 2/3] TST: split test_url and make with @network portion requiring network access --- pandas/io/tests/test_parsers.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index 1c8b7754c500f..c6b096f502598 100644 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -20,7 +20,7 @@ from pandas import DataFrame, Index, isnull from pandas.io.parsers import (read_csv, read_table, read_fwf, ExcelFile, TextParser) -from pandas.util.testing import assert_almost_equal, assert_frame_equal +from pandas.util.testing import assert_almost_equal, assert_frame_equal, network import pandas._tseries as lib from pandas.util import py3compat @@ -798,6 +798,7 @@ def test_na_value_dict(self): assert_frame_equal(df, expected) @slow + @network def test_url(self): # HTTP(S) url = 'https://raw.github.com/pydata/pandas/master/pandas/io/tests/salary.table' @@ -806,10 +807,18 @@ def test_url(self): localtable = os.path.join(dirpath, 'salary.table') local_table = read_table(localtable) assert_frame_equal(url_table, local_table) + #TODO: ftp testing + + @slow + def test_file(self): # FILE + dirpath = curpath() + localtable = os.path.join(dirpath, 'salary.table') + local_table = read_table(localtable) + url_table = read_table('file://localhost/'+localtable) assert_frame_equal(url_table, local_table) - #TODO: ftp testing + class TestParseSQL(unittest.TestCase): From 1e486a58441a3ce300939fb320812578d7884555 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 12 Apr 2012 20:23:07 -0400 Subject: [PATCH 3/3] ENH: skip test_file test with python 2.5 (not supported AFAIK) --- pandas/io/tests/test_parsers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index c6b096f502598..8437875b17060 100644 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -812,6 +812,8 @@ def test_url(self): @slow def test_file(self): # FILE + if sys.version_info[:2] < (2, 6): + raise nose.SkipTest("file:// not supported with Python < 2.6") dirpath = curpath() localtable = os.path.join(dirpath, 'salary.table') local_table = read_table(localtable)