mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-01 23:12:21 +00:00
obbject tests (#5558)
* obbject tests * ruff * fix dev_install * fix unittests * black on nox * black on nox * nox * fix fetcher test so it can compare dates * fix intrinio tests * ruff
This commit is contained in:
@@ -15,4 +15,6 @@ def tests(session):
|
||||
)
|
||||
session.install("pytest")
|
||||
session.install("pytest-cov")
|
||||
session.run("pytest", *test_locations, "--cov=openbb_platform/")
|
||||
session.run(
|
||||
"pytest", *test_locations, "--cov=openbb_platform/", "-m", "not integration"
|
||||
)
|
||||
|
||||
@@ -37,7 +37,6 @@ openbb-alpha-vantage = { path = "./providers/alpha_vantage", optional = true, de
|
||||
openbb-cboe = { path = "./providers/cboe", optional = true, develop = true }
|
||||
openbb-quandl = { path = "./providers/quandl", optional = true, develop = true }
|
||||
openbb-yfinance = { path = "./providers/yfinance", optional = true, develop = true }
|
||||
openbb-oecd= { path = "./providers/oecd", optional = true, develop = true }
|
||||
|
||||
openbb-charting = { path = "./extensions/charting", optional = true, develop = true }
|
||||
openbb-futures = { path = "./extensions/futures", optional = true, develop = true }
|
||||
|
||||
@@ -471,7 +471,17 @@ def test_economy_gdpforecast(params, headers):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"params",
|
||||
[({"start_date": "2023-01-01", "end_date": "2023-06-06", "country": "Portugal"})],
|
||||
[
|
||||
(
|
||||
{
|
||||
"start_date": "2023-01-01",
|
||||
"end_date": "2023-06-06",
|
||||
"country": "Portugal",
|
||||
"group": "gdp",
|
||||
"importance": 3,
|
||||
}
|
||||
)
|
||||
],
|
||||
)
|
||||
@pytest.mark.integration
|
||||
def test_economy_econcal(params, headers):
|
||||
|
||||
86
openbb_platform/platform/core/integration/test_obbject.py
Normal file
86
openbb_platform/platform/core/integration/test_obbject.py
Normal file
@@ -0,0 +1,86 @@
|
||||
import contextlib
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
with contextlib.suppress(ImportError):
|
||||
import polars as pl
|
||||
|
||||
with contextlib.suppress(ImportError):
|
||||
import pandas as pd
|
||||
|
||||
with contextlib.suppress(ImportError):
|
||||
import numpy as np
|
||||
|
||||
with contextlib.suppress(ImportError):
|
||||
from openbb_charting.core.openbb_figure import OpenBBFigure
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def obb(pytestconfig):
|
||||
"""Fixture to setup obb."""
|
||||
|
||||
if pytestconfig.getoption("markexpr") != "not integration":
|
||||
import openbb
|
||||
|
||||
return openbb.obb
|
||||
|
||||
|
||||
@pytest.mark.skipif("pandas" not in sys.modules, reason="pandas not installed")
|
||||
@pytest.mark.integration
|
||||
def test_to_dataframe(obb):
|
||||
"""Test obbject to dataframe."""
|
||||
|
||||
stocks_df = obb.stocks.load("AAPL", provider="fmp").to_dataframe()
|
||||
assert isinstance(stocks_df, pd.DataFrame)
|
||||
|
||||
|
||||
@pytest.mark.skipif("polars" not in sys.modules, reason="polars not installed")
|
||||
@pytest.mark.integration
|
||||
def test_to_polars(obb):
|
||||
"""Test obbject to polars."""
|
||||
|
||||
crypto_pl = obb.crypto.load("BTC-USD", provider="fmp").to_polars()
|
||||
assert isinstance(crypto_pl, pl.DataFrame)
|
||||
|
||||
|
||||
@pytest.mark.skipif("numpy" not in sys.modules, reason="numpy not installed")
|
||||
@pytest.mark.integration
|
||||
def test_to_numpy(obb):
|
||||
"""Test obbject to numpy array."""
|
||||
|
||||
cpi_np = obb.economy.cpi(
|
||||
countries=["portugal", "spain", "switzerland"], frequency="annual"
|
||||
).to_numpy()
|
||||
assert isinstance(cpi_np, np.ndarray)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_to_dict(obb):
|
||||
"""Test obbject to dict."""
|
||||
|
||||
fed_dict = obb.fixedincome.fed(start_date="2010-01-01").to_dict()
|
||||
assert isinstance(fed_dict, dict)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
"openbb_charting" not in sys.modules, reason="openbb_charting not installed"
|
||||
)
|
||||
@pytest.mark.integration
|
||||
def test_to_chart(obb):
|
||||
"""Test obbject to chart."""
|
||||
|
||||
stocks_chart = obb.stocks.load("AAPL", provider="fmp").to_chart()
|
||||
assert isinstance(stocks_chart, OpenBBFigure)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
"openbb_charting" not in sys.modules, reason="openbb_charting not installed"
|
||||
)
|
||||
@pytest.mark.integration
|
||||
def test_show(obb):
|
||||
"""Test obbject to chart."""
|
||||
|
||||
stocks_data = obb.stocks.load("AAPL", provider="fmp", chart=True)
|
||||
assert isinstance(stocks_data.chart.fig, OpenBBFigure)
|
||||
assert stocks_data.chart.fig.show() is None
|
||||
@@ -22,6 +22,7 @@ def test_fields():
|
||||
assert "provider" in fields
|
||||
assert "warnings" in fields
|
||||
assert "chart" in fields
|
||||
assert "extra" in fields
|
||||
|
||||
|
||||
def test_to_dataframe_no_results():
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# ruff: noqa: S101
|
||||
# pylint: disable=E1101
|
||||
|
||||
|
||||
from typing import Any, Dict, Generic, Optional, TypeVar, get_args, get_origin
|
||||
|
||||
from openbb_provider.abstract.data import Data
|
||||
|
||||
@@ -61,6 +61,8 @@ class IntrinioOptionsChainsFetcher(
|
||||
if params.get("date") is None:
|
||||
transform_params["date"] = (now - timedelta(days=1)).strftime("%Y-%m-%d")
|
||||
|
||||
transform_params["date"] = parser.parse(transform_params["date"]).date()
|
||||
|
||||
return IntrinioOptionsChainsQueryParams(**transform_params)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user