-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sample.py
30 lines (21 loc) · 987 Bytes
/
test_sample.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
import pytest
import pandas
import json
from stocks import get_yesterday_trading_prices
from stocks import get_current_trading_prices
@pytest.fixture
def abc_1mo_dataframe() -> pandas.DataFrame:
with open('fixtures/abc_1mo.json') as file:
abc_1mo = json.load(file)
return pandas.DataFrame(abc_1mo)
@pytest.fixture
def abc_1d_dataframe() -> pandas.DataFrame:
with open('fixtures/abc_1d.json') as file:
abc_1d = json.load(file)
return pandas.DataFrame(abc_1d)
def test_yesterday_trading_prices(mocker, abc_1mo_dataframe: pandas.DataFrame) -> None:
mocker.patch("yfinance.Ticker.history", return_value=abc_1mo_dataframe)
assert get_yesterday_trading_prices('ABC') == (171.5099945068, 171.0599975586)
def test_current_trading_prices(mocker, abc_1d_dataframe: pandas.DataFrame) -> None:
mocker.patch("yfinance.Ticker.history", return_value=abc_1d_dataframe)
assert get_current_trading_prices('ABC') == (170.0700073242, 169.8350067139)