mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 13:32:08 +00:00
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import os
|
|
|
|
import pandas as pd
|
|
import pytest
|
|
from _pytest.nodes import Node
|
|
|
|
|
|
def create_path(*path: str) -> str:
|
|
base_path = os.path.dirname(os.path.abspath(__file__))
|
|
in_between = os.path.dirname(base_path)
|
|
default_path = os.path.join(in_between, *path)
|
|
return default_path
|
|
|
|
|
|
@pytest.fixture
|
|
def tsla_csv():
|
|
path = create_path("forecast", "data", "TSLA.csv")
|
|
df = pd.read_csv(path)
|
|
df.columns = [x.lower() for x in df.columns]
|
|
df["date"] = df["date"].apply(lambda x: pd.to_datetime(x))
|
|
return df
|
|
|
|
|
|
def test_model(model, data, *args, **kwargs):
|
|
try:
|
|
_, _, predict, MAPE, _ = model(data, *args, **kwargs)
|
|
except ValueError:
|
|
_, _, predict, MAPE, _, _ = model(data, *args, **kwargs)
|
|
try:
|
|
predict_list = predict.pd_dataframe()["close"].tolist()
|
|
except (AssertionError, KeyError):
|
|
predict_list = predict.quantile_df()
|
|
predict_list = predict_list[predict_list.columns[0]].tolist()
|
|
return predict_list, MAPE
|
|
|
|
|
|
# make same function but for anomaly detection model
|
|
def test_anom_model(model, data, *args, **kwargs):
|
|
ticker_series, anom_score, binary_anom = model(data, *args, **kwargs)
|
|
return ticker_series, anom_score, binary_anom
|
|
|
|
|
|
def pytest_runtest_setup(item: Node):
|
|
if not item.config.getoption("--forecast"):
|
|
pytest.skip(msg="Runs only with option : --forecast")
|