|
1 | 1 | import unittest
|
2 | 2 | import nose
|
3 | 3 | from datetime import datetime
|
| 4 | +import warnings |
4 | 5 |
|
5 | 6 | import pandas as pd
|
6 | 7 | import pandas.io.data as web
|
@@ -102,72 +103,55 @@ def test_options(self):
|
102 | 103 | import lxml
|
103 | 104 | except ImportError:
|
104 | 105 | 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): |
105 | 128 | 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") |
106 | 136 | # aapl has monthlies
|
107 |
| - aapl = web.Options('aapl', 'yahoo') |
| 137 | + aapl = web.Options('aapl') |
108 | 138 | today = datetime.today()
|
109 | 139 | year = today.year
|
110 | 140 | month = today.month+1
|
111 | 141 | if (month>12):
|
112 | 142 | year = year +1
|
113 | 143 | 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) |
171 | 155 |
|
172 | 156 | if __name__ == '__main__':
|
173 | 157 | nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
|
|
0 commit comments