Skip to content

@network decorator for tests requiring network access #1038

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
merged 3 commits into from
Apr 14, 2012
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
15 changes: 13 additions & 2 deletions pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand All @@ -806,10 +807,20 @@ 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
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)

url_table = read_table('file://localhost/'+localtable)
assert_frame_equal(url_table, local_table)
#TODO: ftp testing


class TestParseSQL(unittest.TestCase):

Expand Down
37 changes: 37 additions & 0 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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