import nose

import pandas
from pandas.util.testing import network
from pandas.util.testing import assert_frame_equal
from numpy.testing.decorators import slow
from pandas.io.wb import search, download


@slow
@network
def test_wdi_search():
    raise nose.SkipTest
    expected = {'id': {2634: 'GDPPCKD',
                        4649: 'NY.GDP.PCAP.KD',
                        4651: 'NY.GDP.PCAP.KN',
                        4653: 'NY.GDP.PCAP.PP.KD'},
                'name': {2634: 'GDP per Capita, constant US$, millions',
                          4649: 'GDP per capita (constant 2000 US$)',
                          4651: 'GDP per capita (constant LCU)',
                          4653: 'GDP per capita, PPP (constant 2005 international $)'}}
    result = search('gdp.*capita.*constant').ix[:, :2]
    expected = pandas.DataFrame(expected)
    expected.index = result.index
    assert_frame_equal(result, expected)


@slow
@network
def test_wdi_download():
    raise nose.SkipTest
    expected = {'GDPPCKN': {('United States', '2003'): '40800.0735367688', ('Canada', '2004'): '37857.1261134552', ('United States', '2005'): '42714.8594790102', ('Canada', '2003'): '37081.4575704003', ('United States', '2004'): '41826.1728310667', ('Mexico', '2003'): '72720.0691255285', ('Mexico', '2004'): '74751.6003347038', ('Mexico', '2005'): '76200.2154469437', ('Canada', '2005'): '38617.4563629611'}, 'GDPPCKD': {('United States', '2003'): '40800.0735367688', ('Canada', '2004'): '34397.055116118', ('United States', '2005'): '42714.8594790102', ('Canada', '2003'): '33692.2812368928', ('United States', '2004'): '41826.1728310667', ('Mexico', '2003'): '7608.43848670658', ('Mexico', '2004'): '7820.99026814334', ('Mexico', '2005'): '7972.55364129367', ('Canada', '2005'): '35087.8925933298'}}
    expected = pandas.DataFrame(expected)
    result = download(country=['CA', 'MX', 'US', 'junk'], indicator=['GDPPCKD',
                                                                     'GDPPCKN', 'junk'], start=2003, end=2005)
    expected.index = result.index
    assert_frame_equal(result, pandas.DataFrame(expected))


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