Skip to content

Commit cff50cd

Browse files
committed
Merge pull request #1038 from neurodebian/master
@network decorator for tests requiring network access
2 parents 9d09493 + 1e486a5 commit cff50cd

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

pandas/io/tests/test_parsers.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pandas import DataFrame, Index, isnull
2121
from pandas.io.parsers import (read_csv, read_table, read_fwf,
2222
ExcelFile, TextParser)
23-
from pandas.util.testing import assert_almost_equal, assert_frame_equal
23+
from pandas.util.testing import assert_almost_equal, assert_frame_equal, network
2424
import pandas._tseries as lib
2525
from pandas.util import py3compat
2626

@@ -798,6 +798,7 @@ def test_na_value_dict(self):
798798
assert_frame_equal(df, expected)
799799

800800
@slow
801+
@network
801802
def test_url(self):
802803
# HTTP(S)
803804
url = 'https://raw.github.com/pydata/pandas/master/pandas/io/tests/salary.table'
@@ -806,10 +807,20 @@ def test_url(self):
806807
localtable = os.path.join(dirpath, 'salary.table')
807808
local_table = read_table(localtable)
808809
assert_frame_equal(url_table, local_table)
810+
#TODO: ftp testing
811+
812+
@slow
813+
def test_file(self):
809814
# FILE
815+
if sys.version_info[:2] < (2, 6):
816+
raise nose.SkipTest("file:// not supported with Python < 2.6")
817+
dirpath = curpath()
818+
localtable = os.path.join(dirpath, 'salary.table')
819+
local_table = read_table(localtable)
820+
810821
url_table = read_table('file://localhost/'+localtable)
811822
assert_frame_equal(url_table, local_table)
812-
#TODO: ftp testing
823+
813824

814825
class TestParseSQL(unittest.TestCase):
815826

pandas/util/testing.py

+37
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,40 @@ def skip_if_no_package(*args, **kwargs):
294294
package_check(exc_failed_import=SkipTest,
295295
exc_failed_check=SkipTest,
296296
*args, **kwargs)
297+
298+
#
299+
# Additional tags decorators for nose
300+
#
301+
def network(t):
302+
"""
303+
Label a test as requiring network connection.
304+
305+
In some cases it is not possible to assume network presence (e.g. Debian
306+
build hosts).
307+
308+
Parameters
309+
----------
310+
t : callable
311+
The test requiring network connectivity.
312+
313+
Returns
314+
-------
315+
t : callable
316+
The decorated test `t`.
317+
318+
Examples
319+
--------
320+
A test can be decorated as requiring network like this::
321+
322+
from pandas.util.testing import *
323+
324+
@network
325+
def test_network(self):
326+
print 'Fetch the stars from http://'
327+
328+
And use ``nosetests -a '!network'`` to exclude running tests requiring
329+
network connectivity.
330+
"""
331+
332+
t.network = True
333+
return t

0 commit comments

Comments
 (0)