Skip to content

Commit 6cce5f1

Browse files
OlegShteynbukjreback
authored andcommitted
a signature-preserving decorator using wrapt package
closes #363
1 parent cdd8b4d commit 6cce5f1

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ install:
5151
- conda update -q conda
5252
# Useful for debugging any issues with conda
5353
- conda info -a
54-
- conda create -q -n test-environment python=$PYTHON coverage setuptools html5lib lxml pytest pytest-cov
54+
- conda create -q -n test-environment python=$PYTHON coverage setuptools html5lib lxml pytest pytest-cov wrapt
5555
- source activate test-environment
5656
- if [[ "$PANDAS" == "MASTER" ]]; then
5757
conda install numpy pytz python-dateutil;

pandas_datareader/_testing.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Utilities for testing purposes.
33
"""
44

5-
from functools import wraps
5+
import wrapt
66

77

88
def skip_on_exception(exp):
@@ -11,22 +11,20 @@ def skip_on_exception(exp):
1111
the Exception is raised for reasons beyond our control (e.g.
1212
flakey 3rd-party API).
1313
14+
a signature-preserving decorator
15+
1416
Parameters
1517
----------
1618
exp : The Exception under which to execute try-except.
1719
"""
1820

1921
from pytest import skip
2022

21-
def outer_wrapper(f):
22-
23-
@wraps(f)
24-
def wrapper(*args, **kwargs):
25-
try:
26-
f(*args, **kwargs)
27-
except exp as e:
28-
skip(str(e))
29-
30-
return wrapper
23+
@wrapt.decorator
24+
def wrapper(wrapped, instance, args, kwargs):
25+
try:
26+
return wrapped(*args, **kwargs)
27+
except exp as e:
28+
skip(str(e))
3129

32-
return outer_wrapper
30+
return wrapper

pandas_datareader/tests/yahoo/test_yahoo.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,12 @@ def test_get_data_multiple_symbols(self):
132132
web.get_data_yahoo(sl, '2012')
133133

134134
@pytest.mark.parametrize('adj_pr', [True, False])
135+
@skip_on_exception(RemoteDataError)
135136
def test_get_data_null_as_missing_data(self, adj_pr):
136-
# TODO: We can't decorate the test function along with
137-
# parametrization because it errors. Investigate this later.
138-
@skip_on_exception(RemoteDataError)
139-
def null_as_missing_data(adj_price):
140-
result = web.get_data_yahoo('SRCE', '20160626', '20160705',
141-
adjust_price=adj_pr)
142-
# sanity checking
143-
assert result.dtypes.all() == np.floating
144-
145-
null_as_missing_data(adj_pr)
137+
result = web.get_data_yahoo('SRCE', '20160626', '20160705',
138+
adjust_price=adj_pr)
139+
# sanity checking
140+
assert result.dtypes.all() == np.floating
146141

147142
@skip_on_exception(RemoteDataError)
148143
def test_get_data_multiple_symbols_two_dates(self):

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ commands=
77
deps=
88
pytest
99
pytest-cov
10+
wrapt

0 commit comments

Comments
 (0)