/
test_robinhood.py
48 lines (36 loc) · 1.41 KB
/
test_robinhood.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np
import pandas as pd
import pytest
from pandas_datareader.robinhood import RobinhoodQuoteReader, \
RobinhoodHistoricalReader
syms = ['GOOG', ['GOOG', 'AAPL']]
ids = list(map(str, syms))
@pytest.fixture(params=['GOOG', ['GOOG', 'AAPL']], ids=ids)
def symbols(request):
return request.param
def test_robinhood_quote(symbols):
df = RobinhoodQuoteReader(symbols=symbols).read()
assert isinstance(df, pd.DataFrame)
if isinstance(symbols, str):
symbols = [symbols]
assert df.shape[1] == len(symbols)
def test_robinhood_quote_too_many():
syms = np.random.randint(65, 90, size=(10000, 4)).tolist()
syms = list(map(lambda r: ''.join(map(chr, r)), syms))
syms = list(set(syms))
with pytest.raises(ValueError):
RobinhoodQuoteReader(symbols=syms)
def test_robinhood_historical_too_many():
syms = np.random.randint(65, 90, size=(10000, 4)).tolist()
syms = list(map(lambda r: ''.join(map(chr, r)), syms))
syms = list(set(syms))
with pytest.raises(ValueError):
RobinhoodHistoricalReader(symbols=syms)
with pytest.raises(ValueError):
RobinhoodHistoricalReader(symbols=syms[:76])
def test_robinhood_historical(symbols):
df = RobinhoodHistoricalReader(symbols=symbols).read()
assert isinstance(df, pd.DataFrame)
if isinstance(symbols, str):
symbols = [symbols]
assert df.index.levels[0].shape[0] == len(symbols)