|
| 1 | +from datetime import datetime |
| 2 | +from pandas import DataFrame |
| 3 | +from pandas_datareader.data import * |
| 4 | + |
| 5 | +import nose |
| 6 | +import pandas.util.testing as tm |
| 7 | +from pandas.util.testing import (assert_series_equal, assert_frame_equal) |
| 8 | + |
| 9 | + |
| 10 | +class TestIEX(tm.TestCase): |
| 11 | + @classmethod |
| 12 | + def setUpClass(cls): |
| 13 | + super(TestIEX, cls).setUpClass() |
| 14 | + |
| 15 | + @classmethod |
| 16 | + def tearDownClass(cls): |
| 17 | + super(TestIEX, cls).tearDownClass() |
| 18 | + |
| 19 | + def test_read_iex(self): |
| 20 | + gs = DataReader("GS", "iex-last") |
| 21 | + assert isinstance(gs, DataFrame) |
| 22 | + |
| 23 | + 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) |
| 26 | + |
| 27 | + def test_false_ticker(self): |
| 28 | + df = get_last_iex("INVALID TICKER") |
| 29 | + assert_frame_equal(df, DataFrame()) |
| 30 | + |
| 31 | + def test_daily(self): |
| 32 | + df = get_data_iex(start=datetime(2017, 5, 5), end=datetime(2017, 5, 6)) |
| 33 | + self.assertEqual(df['routedVolume'].iloc[0], 39974788) |
| 34 | + |
| 35 | + def test_symbols(self): |
| 36 | + df = get_iex_symbols() |
| 37 | + self.assertTrue('GS' in df.symbol.values) |
| 38 | + |
| 39 | + def test_live_prices(self): |
| 40 | + dftickers = get_iex_symbols() |
| 41 | + tickers = dftickers[:5].symbol.values |
| 42 | + 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 |
0 commit comments