Skip to content

Commit 394e311

Browse files
committed
Removes tm.TestCase from IEX testing
1 parent 2a676b9 commit 394e311

File tree

6 files changed

+82
-71
lines changed

6 files changed

+82
-71
lines changed

pandas_datareader/iex/__init__.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
from pandas_datareader.base import _BaseReader
55

66
# Data provided for free by IEX
7-
# Data is furnished in compliance with the guidelines promulgated in the IEX API terms of service and manual
8-
# See https://iextrading.com/api-exhibit-a/ for additional information and conditions of use
7+
# Data is furnished in compliance with the guidelines promulgated in the IEX
8+
# API terms of service and manual
9+
# See https://iextrading.com/api-exhibit-a/ for additional information
10+
# and conditions of use
911

1012

1113
class IEX(_BaseReader):
@@ -19,9 +21,9 @@ class IEX(_BaseReader):
1921
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
2022
pause=0.001, session=None):
2123
super(IEX, self).__init__(symbols=symbols,
22-
start=start, end=end,
23-
retry_count=retry_count,
24-
pause=pause, session=session)
24+
start=start, end=end,
25+
retry_count=retry_count,
26+
pause=pause, session=session)
2527

2628
@property
2729
def service(self):
@@ -31,7 +33,8 @@ def service(self):
3133
@property
3234
def url(self):
3335
qstring = urlencode(self._get_params(self.symbols))
34-
return "https://api.iextrading.com/1.0/{}?{}".format(self.service, qstring)
36+
return "https://api.iextrading.com/1.0/{}?{}".format(self.service,
37+
qstring)
3538

3639
def read(self):
3740
df = super(IEX, self).read()
@@ -46,8 +49,9 @@ def _get_params(self, symbols):
4649
return p
4750

4851
def _output_error(self, out):
49-
"""If IEX returns a non-200 status code, we need to notify the user of the error returned.
50-
52+
"""If IEX returns a non-200 status code, we need to notify the user of
53+
the error returned.
54+
5155
:param out: Raw HTTP Output
5256
"""
5357
try:
@@ -61,8 +65,9 @@ def _output_error(self, out):
6165
raise Exception(e)
6266

6367
def _read_lines(self, out):
64-
"""IEX's output does not need anything complex, so we're overriding to use Pandas' default interpreter
65-
68+
"""IEX's output does not need anything complex, so we're overriding to
69+
use Pandas' default interpreter
70+
6671
:param out: Raw HTTP Output
6772
:return: DataFrame
6873
"""

pandas_datareader/iex/market.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
from pandas_datareader.iex import IEX
22

33
# Data provided for free by IEX
4-
# Data is furnished in compliance with the guidelines promulgated in the IEX API terms of service and manual
5-
# See https://iextrading.com/api-exhibit-a/ for additional information and conditions of use
4+
# Data is furnished in compliance with the guidelines promulgated in the IEX
5+
# API terms of service and manual
6+
# See https://iextrading.com/api-exhibit-a/ for additional information
7+
# and conditions of use
68

79

810
class MarketReader(IEX):
911
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
1012
pause=0.001, session=None):
1113
super(MarketReader, self).__init__(symbols=symbols,
12-
start=start, end=end,
13-
retry_count=retry_count,
14-
pause=pause, session=session)
14+
start=start, end=end,
15+
retry_count=retry_count,
16+
pause=pause, session=session)
1517

1618
@property
1719
def service(self):

pandas_datareader/iex/ref.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
from pandas_datareader.iex import IEX
22

33
# Data provided for free by IEX
4-
# Data is furnished in compliance with the guidelines promulgated in the IEX API terms of service and manual
5-
# See https://iextrading.com/api-exhibit-a/ for additional information and conditions of use
4+
# Data is furnished in compliance with the guidelines promulgated in the IEX
5+
# API terms of service and manual
6+
# See https://iextrading.com/api-exhibit-a/ for additional information
7+
# and conditions of use
68

79

810
class SymbolsReader(IEX):
911
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
1012
pause=0.001, session=None):
1113
super(SymbolsReader, self).__init__(symbols=symbols,
12-
start=start, end=end,
13-
retry_count=retry_count,
14-
pause=pause, session=session)
14+
start=start, end=end,
15+
retry_count=retry_count,
16+
pause=pause, session=session)
1517

1618
@property
1719
def service(self):

pandas_datareader/iex/stats.py

+27-21
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
from pandas_datareader.iex import IEX
44

55
# Data provided for free by IEX
6-
# Data is furnished in compliance with the guidelines promulgated in the IEX API terms of service and manual
7-
# See https://iextrading.com/api-exhibit-a/ for additional information and conditions of use
6+
# Data is furnished in compliance with the guidelines promulgated in the IEX
7+
# API terms of service and manual
8+
# See https://iextrading.com/api-exhibit-a/ for additional information
9+
# and conditions of use
810

911

1012
class DailySummaryReader(IEX):
1113
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
1214
pause=0.001, session=None):
1315
self.curr_date = start
1416
super(DailySummaryReader, self).__init__(symbols=symbols,
15-
start=start, end=end,
16-
retry_count=retry_count,
17-
pause=pause, session=session)
17+
start=start, end=end,
18+
retry_count=retry_count,
19+
pause=pause, session=session)
1820

1921
@property
2022
def service(self):
@@ -29,9 +31,10 @@ def _get_params(self, symbols):
2931
return p
3032

3133
def read(self):
32-
"""Unfortunately, IEX's API can only retrieve data one day or one month at a time. Rather than specifying a date
33-
range, we will have to run the read function for each date provided.
34-
34+
"""Unfortunately, IEX's API can only retrieve data one day or one month
35+
at a time. Rather than specifying a date range, we will have to run
36+
the read function for each date provided.
37+
3538
:return: DataFrame
3639
"""
3740
tlen = self.end - self.start
@@ -50,9 +53,10 @@ def __init__(self, symbols=None, start=None, end=None, retry_count=3,
5053
self.date_format = '%Y%m'
5154

5255
super(MonthlySummaryReader, self).__init__(symbols=symbols,
53-
start=start, end=end,
54-
retry_count=retry_count,
55-
pause=pause, session=session)
56+
start=start, end=end,
57+
retry_count=retry_count,
58+
pause=pause,
59+
session=session)
5660

5761
@property
5862
def service(self):
@@ -67,16 +71,18 @@ def _get_params(self, symbols):
6771
return p
6872

6973
def read(self):
70-
"""Unfortunately, IEX's API can only retrieve data one day or one month at a time. Rather than specifying a date
71-
range, we will have to run the read function for each date provided.
72-
74+
"""Unfortunately, IEX's API can only retrieve data one day or one month
75+
at a time. Rather than specifying a date range, we will have to run
76+
the read function for each date provided.
77+
7378
:return: DataFrame
7479
"""
7580
tlen = self.end - self.start
7681
dfs = []
7782

7883
# Build list of all dates within the given range
79-
lrange = [x for x in (self.start + timedelta(n) for n in range(tlen.days))]
84+
lrange = [x for x in (self.start + timedelta(n)
85+
for n in range(tlen.days))]
8086

8187
mrange = []
8288
for dt in lrange:
@@ -101,9 +107,9 @@ class RecordsReader(IEX):
101107
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
102108
pause=0.001, session=None):
103109
super(RecordsReader, self).__init__(symbols=symbols,
104-
start=start, end=end,
105-
retry_count=retry_count,
106-
pause=pause, session=session)
110+
start=start, end=end,
111+
retry_count=retry_count,
112+
pause=pause, session=session)
107113

108114
@property
109115
def service(self):
@@ -118,9 +124,9 @@ class RecentReader(IEX):
118124
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
119125
pause=0.001, session=None):
120126
super(RecentReader, self).__init__(symbols=symbols,
121-
start=start, end=end,
122-
retry_count=retry_count,
123-
pause=pause, session=session)
127+
start=start, end=end,
128+
retry_count=retry_count,
129+
pause=pause, session=session)
124130

125131
@property
126132
def service(self):

pandas_datareader/iex/tops.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
from pandas_datareader.iex import IEX
22

33
# Data provided for free by IEX
4-
# Data is furnished in compliance with the guidelines promulgated in the IEX API terms of service and manual
5-
# See https://iextrading.com/api-exhibit-a/ for additional information and conditions of use
4+
# Data is furnished in compliance with the guidelines promulgated in the IEX
5+
# API terms of service and manual
6+
# See https://iextrading.com/api-exhibit-a/ for additional information
7+
# and conditions of use
68

79

810
class TopsReader(IEX):
911

1012
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
1113
pause=0.001, session=None):
1214
super(TopsReader, self).__init__(symbols=symbols,
13-
start=start, end=end,
14-
retry_count=retry_count,
15-
pause=pause, session=session)
15+
start=start, end=end,
16+
retry_count=retry_count,
17+
pause=pause, session=session)
1618

1719
@property
1820
def service(self):
1921
return "tops"
2022

2123

2224
class LastReader(IEX):
23-
# todo: Eventually we'll want to implement the WebSockets version as an option.
25+
# todo: Eventually we'll want to implement WebSockets as an option.
2426
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
2527
pause=0.001, session=None):
2628
super(LastReader, self).__init__(symbols=symbols,
27-
start=start, end=end,
28-
retry_count=retry_count,
29-
pause=pause, session=session)
29+
start=start, end=end,
30+
retry_count=retry_count,
31+
pause=pause, session=session)
3032

3133
@property
3234
def service(self):

pandas_datareader/tests/test_iex.py

+15-21
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
1-
from datetime import datetime
2-
from pandas import DataFrame
3-
from pandas_datareader.data import *
1+
import pytest
42

5-
import nose
63
import pandas.util.testing as tm
7-
from pandas.util.testing import (assert_series_equal, assert_frame_equal)
84

5+
from pandas import DataFrame
6+
from datetime import datetime
7+
from pandas_datareader.data import (DataReader, get_summary_iex, get_last_iex,
8+
get_data_iex, get_iex_symbols)
99

10-
class TestIEX(tm.TestCase):
11-
@classmethod
12-
def setUpClass(cls):
13-
super(TestIEX, cls).setUpClass()
1410

11+
class TestIEX(object):
1512
@classmethod
16-
def tearDownClass(cls):
17-
super(TestIEX, cls).tearDownClass()
13+
def setup_class(cls):
14+
pytest.importorskip("lxml")
1815

1916
def test_read_iex(self):
2017
gs = DataReader("GS", "iex-last")
2118
assert isinstance(gs, DataFrame)
2219

2320
def test_historical(self):
24-
df = get_summary_iex(start=datetime(2017, 4, 1), end=datetime(2017, 4, 30))
25-
self.assertEqual(df["averageDailyVolume"].iloc[0], 137650908.9)
21+
df = get_summary_iex(start=datetime(2017, 4, 1),
22+
end=datetime(2017, 4, 30))
23+
assert df["averageDailyVolume"].iloc[0] == 137650908.9
2624

2725
def test_false_ticker(self):
2826
df = get_last_iex("INVALID TICKER")
29-
assert_frame_equal(df, DataFrame())
27+
tm.assert_frame_equal(df, DataFrame())
3028

3129
def test_daily(self):
3230
df = get_data_iex(start=datetime(2017, 5, 5), end=datetime(2017, 5, 6))
33-
self.assertEqual(df['routedVolume'].iloc[0], 39974788)
31+
assert df['routedVolume'].iloc[0] == 39974788
3432

3533
def test_symbols(self):
3634
df = get_iex_symbols()
37-
self.assertTrue('GS' in df.symbol.values)
35+
assert 'GS' in df.symbol.values
3836

3937
def test_live_prices(self):
4038
dftickers = get_iex_symbols()
4139
tickers = dftickers[:5].symbol.values
4240
df = get_last_iex(tickers[:5])
43-
self.assertGreater(df["price"].mean(), 0)
44-
45-
if __name__ == '__main__':
46-
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
47-
exit=False) # pragma: no cover
41+
assert df["price"].mean() > 0

0 commit comments

Comments
 (0)