Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ python:
- "3.6"
- "3.7"
- "2.7"
- "3.4"
- "3.5"
- "3.8-dev"
- "3.8"
install:
# command to install dependencies
- pip install -r requirements-dev.txt
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
0.1.1 (2020-04-05)
==================

Added
-----

- When an error occur, print the URL that was used for the request (#1)
- Test that data for all the indicators (but `TRD-CMPLMNTRTY-NDX`) can be downloaded (#1)


0.1.0 (2019-11-25)
==================

Expand Down
44 changes: 44 additions & 0 deletions tests/test_get_indicator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest
import requests
import pandas as pd
from world_trade_data import get_indicator, get_indicators


def test_get_indicators():
df = get_indicators()
assert isinstance(df, pd.DataFrame)
assert len(df.index)
assert 'TRD-CMPLMNTRTY-NDX' in df.index


@pytest.mark.parametrize('indicator', ['MPRT-TRD-VL', 'XPRT-TRD-VL', 'WRLD-GRWTH'])
def test_get_indicator(indicator):
df = get_indicator(indicator, 'usa')
assert isinstance(df, pd.DataFrame)
assert len(df.index)


def test_error_on_wrong_indicator(indicator='INCORRECT'):
with pytest.raises(requests.exceptions.RequestException, match='http://wits.worldbank.org'):
get_indicator(indicator, 'usa')


def test_error_on_wrong_partner(indicator='NMBR-XPRT-PRTNR'):
with pytest.raises(requests.exceptions.RequestException, match='http://wits.worldbank.org'):
get_indicator(indicator, 'usa')


@pytest.mark.parametrize('indicator', get_indicators().query('SDMX_partnervalue==""').index)
def test_get_all_indicators(indicator):
if indicator == 'TRD-CMPLMNTRTY-NDX':
pytest.xfail('TRD-CMPLMNTRTY-NDX is not available - cf. https://github.com/mwouts/world_trade_data/issues/1')
df = get_indicator(indicator, 'usa')
assert isinstance(df, pd.DataFrame)
assert len(df.index)


@pytest.mark.parametrize('indicator', get_indicators().query('SDMX_partnervalue=="999"').index)
def test_get_all_indicators_no_partner(indicator):
df = get_indicator(indicator, 'usa', partner='999')
assert isinstance(df, pd.DataFrame)
assert len(df.index)
7 changes: 5 additions & 2 deletions world_trade_data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ def _get_data(reporter, partner, product, year, datasource, name_or_id, **kwargs
if ('all' in reporter.lower() and 'all' in partner.lower()) or sum(['all' in args[k] for k in args]) >= 3:
LOGGER.warning(LIMITATIONS)

response = requests.get('http://wits.worldbank.org/API/V1/SDMX/V21/{}?format=JSON'
.format('/'.join(list_args)))
url = 'http://wits.worldbank.org/API/V1/SDMX/V21/{}?format=JSON'.format('/'.join(list_args))
try:
response = requests.get(url)
except requests.exceptions.RequestException as err:
raise requests.exceptions.RequestException('While requesting {}, an error occured: {}'.format(url, err))
response.raise_for_status()
data = response.json()
return _wits_data_to_df(data, name_or_id=name_or_id)
Expand Down
2 changes: 1 addition & 1 deletion world_trade_data/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""version number"""

__version__ = '0.1.0'
__version__ = '0.1.1'