10
10
11
11
class TestGoogle (unittest .TestCase ):
12
12
13
- @with_connectivity_check ( "http://www.google.com" )
13
+ @network
14
14
def test_google (self ):
15
15
# asserts that google is minimally working and that it throws
16
16
# an exception when DataReader can't get a 200 response from
@@ -22,51 +22,51 @@ def test_google(self):
22
22
web .DataReader ("F" , 'google' , start , end )['Close' ][- 1 ],
23
23
13.68 )
24
24
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 )
30
27
31
28
@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' ]))
35
32
36
- @with_connectivity_check ( 'http://www.google.com' )
33
+ @network
37
34
def test_get_goog_volume (self ):
38
35
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 )
40
37
41
- @with_connectivity_check ( 'http://www.google.com' )
38
+ @network
42
39
def test_get_multi1 (self ):
43
40
sl = ['AAPL' , 'AMZN' , 'GOOG' ]
44
41
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
47
42
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
49
54
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 )
54
59
55
60
# 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 )
59
62
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 )
66
69
67
- # sanity checking
68
- t = np .array (pan )
69
- assert np .issubdtype (t .dtype , np .floating )
70
70
71
71
if __name__ == '__main__' :
72
72
nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
0 commit comments