Skip to content

Commit fd32e09

Browse files
authored
Merge pull request #479 from bashtage/improve-coverage-report
TST: Add additional tests to tiingo
2 parents 4a014c5 + 2cea674 commit fd32e09

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ include = */pandas_datareader/*
66
omit =
77
*/_version.py
88
*/yahoo/*
9+
*/edgar.py
910
*/google/options.py
1011
*/google/quotes.py
1112
*/tests/google/test_options.py
13+
*/tests/test_edgar.py
1214

1315
[report]
1416
# Regexes for lines to exclude from consideration

pandas_datareader/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ def _get_response(self, url, params=None, headers=None):
125125

126126
# initial attempt + retry
127127
pause = self.pause
128+
last_response_text = ''
128129
for i in range(self.retry_count + 1):
129130
response = self.session.get(url,
130131
params=params,
131132
headers=headers)
132133
if response.status_code == requests.codes.ok:
133134
return response
134135

136+
last_response_text = response.text.encode(response.encoding)
135137
time.sleep(pause)
136138

137139
# Increase time between subsequent requests, per subclass.
@@ -146,8 +148,11 @@ def _get_response(self, url, params=None, headers=None):
146148

147149
if params is not None and len(params) > 0:
148150
url = url + "?" + urlencode(params)
151+
msg = 'Unable to read URL: {0}'.format(url)
152+
if last_response_text:
153+
msg += '\nResponse Text:\n{0}'.format(last_response_text)
149154

150-
raise RemoteDataError('Unable to read URL: {0}'.format(url))
155+
raise RemoteDataError(msg)
151156

152157
def _get_crumb(self, *args):
153158
""" To be implemented by subclass """

pandas_datareader/compat/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# flake8: noqa
2+
import sys
3+
from distutils.version import LooseVersion
4+
from io import BytesIO
5+
26
import pandas as pd
3-
import pandas.io.common as com
47
import pandas.compat as compat
8+
import pandas.io.common as com
59

6-
from io import BytesIO
7-
from distutils.version import LooseVersion
10+
PY3 = sys.version_info >= (3, 0)
811

912
PANDAS_VERSION = LooseVersion(pd.__version__)
1013

pandas_datareader/tests/test_tiingo.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import pandas as pd
44
import pytest
55

6+
from pandas_datareader.compat import PY3
67
from pandas_datareader.tiingo import TiingoDailyReader, TiingoMetaDataReader, \
7-
TiingoQuoteReader
8+
TiingoQuoteReader, get_tiingo_symbols
89

910
TEST_API_KEY = os.getenv('TIINGO_API_KEY')
11+
# Ensure blank TEST_API_KEY not used in pull request
12+
TEST_API_KEY = None if not TEST_API_KEY else TEST_API_KEY
1013

1114
syms = ['GOOG', ['GOOG', 'XOM']]
1215
ids = list(map(str, syms))
@@ -42,3 +45,18 @@ def test_tiingo_metadata(symbols):
4245
if isinstance(symbols, str):
4346
symbols = [symbols]
4447
assert df.shape[1] == len(symbols)
48+
49+
50+
@pytest.mark.skipif(not PY3, reason='test.support missing on Python 2')
51+
def test_tiingo_no_api_key(symbols):
52+
from test.support import EnvironmentVarGuard
53+
env = EnvironmentVarGuard()
54+
env.unset('TIINGO_API_KEY')
55+
with env:
56+
with pytest.raises(ValueError):
57+
TiingoMetaDataReader(symbols=symbols)
58+
59+
60+
def test_tiingo_stock_symbols():
61+
sym = get_tiingo_symbols()
62+
assert isinstance(sym, pd.DataFrame)

pandas_datareader/tiingo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def __init__(self, symbols, start=None, end=None, retry_count=3, pause=0.1,
5858
self.symbols = [self.symbols]
5959
self._symbol = ''
6060
if api_key is None:
61-
api_key = os.environ.get('TIINGO_API_KEY', None)
62-
if api_key is None:
61+
api_key = os.getenv('TIINGO_API_KEY')
62+
if not api_key or not isinstance(api_key, str):
6363
raise ValueError('The tiingo API key must be provided either '
6464
'through the api_key variable or through the '
6565
'environmental variable TIINGO_API_KEY.')

0 commit comments

Comments
 (0)