Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obbject tests #5558

Merged
merged 10 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
1 change: 0 additions & 1 deletion openbb_platform/dev_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
86 changes: 86 additions & 0 deletions openbb_platform/platform/core/integration/test_obbject.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def transform_query(params: Dict[str, Any]) -> IntrinioOptionsChainsQueryParams:
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
Expand Down
Loading