1010
1111class TestGoogle (unittest .TestCase ):
1212
13- @with_connectivity_check ( "http://www.google.com" )
13+ @network
1414 def test_google (self ):
1515 # asserts that google is minimally working and that it throws
1616 # an exception when DataReader can't get a 200 response from
@@ -22,51 +22,51 @@ def test_google(self):
2222 web .DataReader ("F" , 'google' , start , end )['Close' ][- 1 ],
2323 13.68 )
2424
25- self .assertRaises (
26- Exception ,
27- lambda : web .DataReader ("NON EXISTENT TICKER" , 'google' ,
28- start , end ))
29-
25+ self .assertRaises (Exception , web .DataReader , "NON EXISTENT TICKER" ,
26+ 'google' , start , end )
3027
3128 @network
32- def test_get_quote (self ):
33- self .assertRaises (NotImplementedError ,
34- lambda : web . get_quote_google ( pd .Series (['GOOG' , 'AAPL' , 'GOOG' ]) ))
29+ def test_get_quote_fails (self ):
30+ self .assertRaises (NotImplementedError , web . get_quote_google ,
31+ pd .Series (['GOOG' , 'AAPL' , 'GOOG' ]))
3532
36- @with_connectivity_check ( 'http://www.google.com' )
33+ @network
3734 def test_get_goog_volume (self ):
3835 df = web .get_data_google ('GOOG' )
39- assert df .Volume .ix ['OCT-08-2010' ] == 2863473
36+ self . assertEqual ( df .Volume .ix ['OCT-08-2010' ], 2863473 )
4037
41- @with_connectivity_check ( 'http://www.google.com' )
38+ @network
4239 def test_get_multi1 (self ):
4340 sl = ['AAPL' , 'AMZN' , 'GOOG' ]
4441 pan = web .get_data_google (sl , '2012' )
45- ts = pan .Close .GOOG .index [pan .Close .AAPL > pan .Close .GOOG ]
46- assert ts [0 ].dayofyear == 96
4742
48- @with_connectivity_check ('http://www.google.com' )
43+ def testit ():
44+ ts = pan .Close .GOOG .index [pan .Close .AAPL > pan .Close .GOOG ]
45+ self .assertEquals (ts [0 ].dayofyear , 96 )
46+
47+ if (hasattr (pan , 'Close' ) and hasattr (pan .Close , 'GOOG' ) and
48+ hasattr (pan .Close , 'AAPL' )):
49+ testit ()
50+ else :
51+ self .assertRaises (AttributeError , testit )
52+
53+ @network
4954 def test_get_multi2 (self ):
50- pan = web .get_data_google (['GE' , 'MSFT' , 'INTC' ], 'JAN-01-12' , 'JAN-31-12' )
51- expected = [ 19.02 , 28.23 , 25.39 ]
52- result = pan .Close .ix ['01-18-12' ][[ 'GE' , 'MSFT' , 'INTC' ]]. tolist ()
53- assert result == expected
55+ pan = web .get_data_google (['GE' , 'MSFT' , 'INTC' ], 'JAN-01-12' ,
56+ 'JAN-31-12' )
57+ result = pan .Close .ix ['01-18-12' ]
58+ self . assertEqual ( len ( result ), 3 )
5459
5560 # sanity checking
56- t = np .array (result )
57- assert np .issubdtype (t .dtype , np .floating )
58- assert t .shape == (3 ,)
61+ assert np .issubdtype (result .dtype , np .floating )
5962
60- expected = [[ 18.99 , 28.4 , 25.18 ],
61- [ 18.58 , 28.31 , 25.13 ],
62- [ 19.03 , 28.16 , 25.52 ],
63- [ 18.81 , 28.82 , 25.87 ]]
64- result = pan .Open .ix ['Jan-15-12' :'Jan-20-12' ][[ 'GE' , 'MSFT' , 'INTC' ]]. values
65- assert ( result == expected ).all ( )
63+ expected = np . array ( [[ 18.99 , 28.4 , 25.18 ],
64+ [ 18.58 , 28.31 , 25.13 ],
65+ [ 19.03 , 28.16 , 25.52 ],
66+ [ 18.81 , 28.82 , 25.87 ]])
67+ result = pan .Open .ix ['Jan-15-12' :'Jan-20-12' ]
68+ self . assertEqual ( np . array ( expected ).shape , result . shape )
6669
67- # sanity checking
68- t = np .array (pan )
69- assert np .issubdtype (t .dtype , np .floating )
7070
7171if __name__ == '__main__' :
7272 nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
0 commit comments