3
3
import warnings
4
4
import nose
5
5
from nose .tools import assert_equal
6
- from datetime import datetime , date
6
+ from datetime import datetime
7
7
import os
8
8
9
9
import numpy as np
21
21
else :
22
22
from urllib2 import HTTPError
23
23
24
+
24
25
def _skip_if_no_lxml ():
25
26
try :
26
27
import lxml
@@ -125,8 +126,8 @@ def test_yahoo(self):
125
126
start = datetime (2010 , 1 , 1 )
126
127
end = datetime (2013 , 1 , 27 )
127
128
128
- self .assertEqual ( web .DataReader ("F" , 'yahoo' , start ,
129
- end )[ 'Close' ][ - 1 ], 13.68 )
129
+ self .assertEqual (web .DataReader ("F" , 'yahoo' , start , end )[ 'Close' ][ - 1 ] ,
130
+ 13.68 )
130
131
131
132
@network
132
133
def test_yahoo_fails (self ):
@@ -200,17 +201,18 @@ def test_get_data_multiple_symbols(self):
200
201
201
202
@network
202
203
def test_get_data_multiple_symbols_two_dates (self ):
203
- pan = web .get_data_yahoo (['GE' , 'MSFT' , 'INTC' ], 'JAN-01-12' , 'JAN-31-12' )
204
+ pan = web .get_data_yahoo (['GE' , 'MSFT' , 'INTC' ], 'JAN-01-12' ,
205
+ 'JAN-31-12' )
204
206
result = pan .Close .ix ['01-18-12' ]
205
207
self .assertEqual (len (result ), 3 )
206
208
207
209
# sanity checking
208
210
assert np .issubdtype (result .dtype , np .floating )
209
211
210
- expected = np .array ([[ 18.99 , 28.4 , 25.18 ],
211
- [ 18.58 , 28.31 , 25.13 ],
212
- [ 19.03 , 28.16 , 25.52 ],
213
- [ 18.81 , 28.82 , 25.87 ]])
212
+ expected = np .array ([[18.99 , 28.4 , 25.18 ],
213
+ [18.58 , 28.31 , 25.13 ],
214
+ [19.03 , 28.16 , 25.52 ],
215
+ [18.81 , 28.82 , 25.87 ]])
214
216
result = pan .Open .ix ['Jan-15-12' :'Jan-20-12' ]
215
217
self .assertEqual (expected .shape , result .shape )
216
218
@@ -249,49 +251,44 @@ def setUpClass(cls):
249
251
cls .root1 = cls .aapl ._parse_url (cls .html1 )
250
252
cls .root2 = cls .aapl ._parse_url (cls .html2 )
251
253
252
-
253
254
@classmethod
254
255
def tearDownClass (cls ):
255
256
super (TestYahooOptions , cls ).tearDownClass ()
256
257
del cls .aapl , cls .expiry
257
258
258
259
@network
259
260
def test_get_options_data (self ):
261
+ # regression test GH6105
262
+ self .assertRaises (ValueError , self .aapl .get_options_data , month = 3 )
263
+ self .assertRaises (ValueError , self .aapl .get_options_data , year = 1992 )
264
+
260
265
try :
261
266
options = self .aapl .get_options_data (expiry = self .expiry )
262
267
except RemoteDataError as e :
263
268
nose .SkipTest (e )
264
269
else :
265
- assert len (options )> 1
266
-
267
-
268
- def test_get_options_data (self ):
269
-
270
- # regression test GH6105
271
- self .assertRaises (ValueError , self .aapl .get_options_data , month = 3 )
272
- self .assertRaises (ValueError , self .aapl .get_options_data , year = 1992 )
270
+ assert len (options ) > 1
273
271
274
272
@network
275
273
def test_get_near_stock_price (self ):
276
274
try :
277
275
options = self .aapl .get_near_stock_price (call = True , put = True ,
278
- expiry = self .expiry )
276
+ expiry = self .expiry )
279
277
except RemoteDataError as e :
280
278
nose .SkipTest (e )
281
279
else :
282
- assert len (options )> 1
280
+ assert len (options ) > 1
283
281
284
282
self .assertTrue (len (options ) > 1 )
285
283
286
-
287
284
@network
288
285
def test_get_call_data (self ):
289
286
try :
290
287
calls = self .aapl .get_call_data (expiry = self .expiry )
291
288
except RemoteDataError as e :
292
289
nose .SkipTest (e )
293
290
else :
294
- assert len (calls )> 1
291
+ assert len (calls ) > 1
295
292
296
293
@network
297
294
def test_get_put_data (self ):
@@ -300,7 +297,7 @@ def test_get_put_data(self):
300
297
except RemoteDataError as e :
301
298
nose .SkipTest (e )
302
299
else :
303
- assert len (puts )> 1
300
+ assert len (puts ) > 1
304
301
305
302
@network
306
303
def test_get_expiry_months (self ):
@@ -328,18 +325,21 @@ def test_get_all_data_calls_only(self):
328
325
329
326
self .assertTrue (len (data ) > 1 )
330
327
328
+ @network
331
329
def test_sample_page_price_quote_time1 (self ):
332
330
#Tests the weekend quote time format
333
331
price , quote_time = self .aapl ._get_underlying_price (self .root1 )
334
332
self .assertIsInstance (price , (int , float , complex ))
335
333
self .assertIsInstance (quote_time , (datetime , Timestamp ))
336
334
335
+ @network
337
336
def test_sample_page_price_quote_time2 (self ):
338
337
#Tests the weekday quote time format
339
338
price , quote_time = self .aapl ._get_underlying_price (self .root2 )
340
339
self .assertIsInstance (price , (int , float , complex ))
341
340
self .assertIsInstance (quote_time , (datetime , Timestamp ))
342
341
342
+ @network
343
343
def test_sample_page_chg_float (self ):
344
344
#Tests that numeric columns with comma's are appropriately dealt with
345
345
tables = self .root1 .xpath ('.//table' )
@@ -348,7 +348,6 @@ def test_sample_page_chg_float(self):
348
348
self .assertEqual (option_data ['Chg' ].dtype , 'float64' )
349
349
350
350
351
-
352
351
class TestOptionsWarnings (tm .TestCase ):
353
352
@classmethod
354
353
def setUpClass (cls ):
@@ -383,9 +382,9 @@ def test_get_near_stock_price_warning(self):
383
382
with assert_produces_warning ():
384
383
try :
385
384
options_near = self .aapl .get_near_stock_price (call = True ,
386
- put = True ,
387
- month = self .month ,
388
- year = self .year )
385
+ put = True ,
386
+ month = self .month ,
387
+ year = self .year )
389
388
except RemoteDataError as e :
390
389
nose .SkipTest (e )
391
390
@@ -430,7 +429,7 @@ def test_read_fred(self):
430
429
def test_read_famafrench (self ):
431
430
for name in ("F-F_Research_Data_Factors" ,
432
431
"F-F_Research_Data_Factors_weekly" , "6_Portfolios_2x3" ,
433
- "F-F_ST_Reversal_Factor" ,"F-F_Momentum_Factor" ):
432
+ "F-F_ST_Reversal_Factor" , "F-F_Momentum_Factor" ):
434
433
ff = DataReader (name , "famafrench" )
435
434
assert ff
436
435
assert isinstance (ff , dict )
@@ -508,6 +507,7 @@ def test_fred_multi_bad_series(self):
508
507
with tm .assertRaises (HTTPError ):
509
508
DataReader (names , data_source = "fred" )
510
509
510
+
511
511
if __name__ == '__main__' :
512
512
nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
513
513
exit = False )
0 commit comments