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:
Henrique Joaquim
2023-10-13 11:39:33 +01:00
committed by GitHub
parent 2e0cd88039
commit 3e8043f97a
7 changed files with 103 additions and 4 deletions

View File

@@ -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"
)

View File

@@ -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 }

View File

@@ -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):

View 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

View File

@@ -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():

View File

@@ -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

View File

@@ -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