Skip to content

Commit ae388a2

Browse files
committed
@network now catches connectivity problems
1 parent f597732 commit ae388a2

File tree

1 file changed

+42
-58
lines changed

1 file changed

+42
-58
lines changed

pandas/io/tests/test_yahoo.py

+42-58
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import nose
33
from datetime import datetime
4+
import warnings
45

56
import pandas as pd
67
import pandas.io.data as web
@@ -102,72 +103,55 @@ def test_options(self):
102103
import lxml
103104
except ImportError:
104105
raise nose.SkipTest
106+
# aapl has monthlies
107+
aapl = web.Options('aapl', 'yahoo')
108+
today = datetime.today()
109+
year = today.year
110+
month = today.month+1
111+
if (month>12):
112+
year = year +1
113+
month = 1
114+
expiry=datetime(year, month, 1)
115+
(calls, puts) = aapl.get_options_data(expiry=expiry)
116+
assert len(calls)>1
117+
assert len(puts)>1
118+
(calls, puts) = aapl.get_near_stock_price(call=True, put=True, expiry=expiry)
119+
assert len(calls)==5
120+
assert len(puts)==5
121+
calls = aapl.get_call_data(expiry=expiry)
122+
assert len(calls)>1
123+
puts = aapl.get_put_data(expiry=expiry)
124+
assert len(puts)>1
125+
126+
@network
127+
def test_options_warnings(self):
105128
try:
129+
import lxml
130+
except ImportError:
131+
raise nose.SkipTest
132+
with warnings.catch_warnings(record=True) as w:
133+
warnings.resetwarnings()
134+
# Cause all warnings to always be triggered.
135+
warnings.simplefilter("always")
106136
# aapl has monthlies
107-
aapl = web.Options('aapl', 'yahoo')
137+
aapl = web.Options('aapl')
108138
today = datetime.today()
109139
year = today.year
110140
month = today.month+1
111141
if (month>12):
112142
year = year +1
113143
month = 1
114-
expiry=datetime(year, month, 1)
115-
(calls, puts) = aapl.get_options_data(expiry=expiry)
116-
assert len(calls)>1
117-
assert len(puts)>1
118-
(calls, puts) = aapl.get_near_stock_price(call=True, put=True, expiry=expiry)
119-
assert len(calls)==5
120-
assert len(puts)==5
121-
calls = aapl.get_call_data(expiry=expiry)
122-
assert len(calls)>1
123-
puts = aapl.get_put_data(expiry=expiry)
124-
assert len(puts)>1
125-
except IOError:
126-
try:
127-
urllib2.urlopen('http://www.google.com')
128-
except IOError:
129-
raise nose.SkipTest
130-
else:
131-
raise
132-
133-
@network
134-
def test_options_warnings(self):
135-
try:
136-
import lxml
137-
except ImportError:
138-
raise nose.SkipTest
139-
try:
140-
import warnings
141-
with warnings.catch_warnings(record=True) as w:
142-
warnings.resetwarnings()
143-
# Cause all warnings to always be triggered.
144-
warnings.simplefilter("always")
145-
# aapl has monthlies
146-
aapl = web.Options('aapl')
147-
today = datetime.today()
148-
year = today.year
149-
month = today.month+1
150-
if (month>12):
151-
year = year +1
152-
month = 1
153-
(calls, puts) = aapl.get_options_data(month=month, year=year)
154-
(calls, puts) = aapl.get_near_stock_price(call=True, put=True, month=month, year=year)
155-
calls = aapl.get_call_data(month=month, year=year)
156-
puts = aapl.get_put_data(month=month, year=year)
157-
print(w)
158-
assert len(w) == 5
159-
assert "deprecated" in str(w[0].message)
160-
assert "deprecated" in str(w[1].message)
161-
assert "deprecated" in str(w[2].message)
162-
assert "deprecated" in str(w[3].message)
163-
assert "deprecated" in str(w[4].message)
164-
except IOError:
165-
try:
166-
urllib2.urlopen('http://www.google.com')
167-
except IOError:
168-
raise nose.SkipTest
169-
else:
170-
raise
144+
(calls, puts) = aapl.get_options_data(month=month, year=year)
145+
(calls, puts) = aapl.get_near_stock_price(call=True, put=True, month=month, year=year)
146+
calls = aapl.get_call_data(month=month, year=year)
147+
puts = aapl.get_put_data(month=month, year=year)
148+
print(w)
149+
assert len(w) == 5
150+
assert "deprecated" in str(w[0].message)
151+
assert "deprecated" in str(w[1].message)
152+
assert "deprecated" in str(w[2].message)
153+
assert "deprecated" in str(w[3].message)
154+
assert "deprecated" in str(w[4].message)
171155

172156
if __name__ == '__main__':
173157
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

0 commit comments

Comments
 (0)