Skip to content

Skip tests on network error #3893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 38 additions & 31 deletions pandas/io/tests/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,44 @@ def test_get_quote(self):

@network
def test_get_data(self):
import numpy as np
df = web.get_data_google('GOOG')
print(df.Volume.ix['OCT-08-2010'])
assert df.Volume.ix['OCT-08-2010'] == 2863473

sl = ['AAPL', 'AMZN', 'GOOG']
pan = web.get_data_google(sl, '2012')
ts = pan.Close.GOOG.index[pan.Close.AAPL > pan.Close.GOOG]
assert ts[0].dayofyear == 96

pan = web.get_data_google(['GE', 'MSFT', 'INTC'], 'JAN-01-12', 'JAN-31-12')
expected = [19.02, 28.23, 25.39]
result = pan.Close.ix['01-18-12'][['GE', 'MSFT', 'INTC']].tolist()
assert result == expected

# sanity checking
t= np.array(result)
assert np.issubdtype(t.dtype, np.floating)
assert t.shape == (3,)

expected = [[ 18.99, 28.4 , 25.18],
[ 18.58, 28.31, 25.13],
[ 19.03, 28.16, 25.52],
[ 18.81, 28.82, 25.87]]
result = pan.Open.ix['Jan-15-12':'Jan-20-12'][['GE', 'MSFT', 'INTC']].values
assert (result == expected).all()

# sanity checking
t= np.array(pan)
assert np.issubdtype(t.dtype, np.floating)

try:
import numpy as np
df = web.get_data_google('GOOG')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example just wrap this in a try clause like so:

import numpy as np
try:
    df = web.get_data_google('GOOG')
except IOError:
    pass
else:
    print(df.Volume.ix['OCT-08-2010'])
    assert df.Volume.ix['OCT-08-2010'] == 2863473

print(df.Volume.ix['OCT-08-2010'])
assert df.Volume.ix['OCT-08-2010'] == 2863473

sl = ['AAPL', 'AMZN', 'GOOG']
pan = web.get_data_google(sl, '2012')
ts = pan.Close.GOOG.index[pan.Close.AAPL > pan.Close.GOOG]
assert ts[0].dayofyear == 96

pan = web.get_data_google(['GE', 'MSFT', 'INTC'], 'JAN-01-12', 'JAN-31-12')
expected = [19.02, 28.23, 25.39]
result = pan.Close.ix['01-18-12'][['GE', 'MSFT', 'INTC']].tolist()
assert result == expected

# sanity checking
t= np.array(result)
assert np.issubdtype(t.dtype, np.floating)
assert t.shape == (3,)

expected = [[ 18.99, 28.4 , 25.18],
[ 18.58, 28.31, 25.13],
[ 19.03, 28.16, 25.52],
[ 18.81, 28.82, 25.87]]
result = pan.Open.ix['Jan-15-12':'Jan-20-12'][['GE', 'MSFT', 'INTC']].values
assert (result == expected).all()

# sanity checking
t= np.array(pan)
assert np.issubdtype(t.dtype, np.floating)
except IOError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be best if use a try:... suite whereever you perform io (and nowhere else) rather than just wrapping everything into a huge try: clause. it's going to be a huge pain to track down which of these is throwing the io error down the line. as a rule try (no pun intended) keeping try: clauses as small as possible so that disambiguating errors is easier. also no need to put any of the post io code in the try:... suite since if you're there there wasn't a raise

try:
urllib2.urlopen('http://www.google.com')
except IOError:
raise nose.SkipTest
else:
raise

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