mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
[Bug fix] - Fix integration tests (#6170)
* fix integration tests * rebuild * unittest
This commit is contained in:
@@ -88,6 +88,7 @@ AppLoader.from_routers(
|
||||
@app.exception_handler(Exception)
|
||||
async def api_exception_handler(_: Request, exc: Exception):
|
||||
"""Exception handler for all other exceptions."""
|
||||
logger.error(exc)
|
||||
return JSONResponse(
|
||||
status_code=404,
|
||||
content={
|
||||
@@ -100,6 +101,7 @@ async def api_exception_handler(_: Request, exc: Exception):
|
||||
@app.exception_handler(OpenBBError)
|
||||
async def openbb_exception_handler(_: Request, exc: OpenBBError):
|
||||
"""Exception handler for OpenBB errors."""
|
||||
logger.error(exc.original)
|
||||
openbb_error = exc.original
|
||||
status_code = 400 if "No results" in str(openbb_error) else 500
|
||||
return JSONResponse(
|
||||
|
||||
@@ -1675,7 +1675,7 @@ def test_equity_darkpool_otc(params, headers):
|
||||
"params",
|
||||
[
|
||||
({"provider": "fmp", "market": "euronext"}),
|
||||
({"provider": "polygon"}), # premium endpoint
|
||||
# ({"provider": "polygon"}), # premium endpoint
|
||||
],
|
||||
)
|
||||
@pytest.mark.integration
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Python interface integration tests for the equity extension."""
|
||||
|
||||
from datetime import time
|
||||
from datetime import date, time, timedelta
|
||||
|
||||
import pytest
|
||||
from extensions.tests.conftest import parametrize
|
||||
@@ -767,8 +767,6 @@ def test_equity_fundamental_revenue_per_segment(params, obb):
|
||||
"symbol": "IBM:US",
|
||||
"start_date": "2023-09-30",
|
||||
"end_date": "2023-12-31",
|
||||
"limit": None,
|
||||
"form_type": None,
|
||||
}
|
||||
),
|
||||
],
|
||||
@@ -878,8 +876,8 @@ def test_equity_compare_groups(params, obb):
|
||||
{
|
||||
"provider": "cboe",
|
||||
"symbol": "AAPL",
|
||||
"start_date": "2024-02-19",
|
||||
"end_date": "2024-02-20",
|
||||
"start_date": (date.today() - timedelta(days=1)).strftime("%Y-%m-%d"),
|
||||
"end_date": date.today().strftime("%Y-%m-%d"),
|
||||
"interval": "1m",
|
||||
"use_cache": False,
|
||||
}
|
||||
@@ -1572,7 +1570,7 @@ def test_equity_darkpool_otc(params, obb):
|
||||
"params",
|
||||
[
|
||||
({"provider": "fmp", "market": "euronext"}),
|
||||
({"provider": "polygon"}), # premium endpoint
|
||||
# ({"provider": "polygon"}), # premium endpoint
|
||||
],
|
||||
)
|
||||
@pytest.mark.integration
|
||||
|
||||
@@ -26,9 +26,11 @@ def get_headers():
|
||||
return data["headers"]
|
||||
|
||||
|
||||
def request_data(menu: str, symbol: str, provider: str):
|
||||
def request_data(
|
||||
menu: str, symbol: str, provider: str, start_date: str = "", end_date: str = ""
|
||||
):
|
||||
"""Randomly pick a symbol and a provider and get data from the selected menu."""
|
||||
url = f"http://0.0.0.0:8000/api/v1/{menu}/price/historical?symbol={symbol}&provider={provider}"
|
||||
url = f"http://0.0.0.0:8000/api/v1/{menu}/price/historical?symbol={symbol}&provider={provider}&start_date={start_date}&end_date={end_date}"
|
||||
result = requests.get(url, headers=get_headers(), timeout=10)
|
||||
return result.json()["results"]
|
||||
|
||||
@@ -40,7 +42,13 @@ def get_stocks_data():
|
||||
symbol = random.choice(["AAPL", "NVDA", "MSFT", "TSLA", "AMZN", "V"]) # noqa: S311
|
||||
provider = random.choice(["fmp", "polygon", "yfinance"]) # noqa: S311
|
||||
|
||||
data["stocks_data"] = request_data("equity", symbol=symbol, provider=provider)
|
||||
data["stocks_data"] = request_data(
|
||||
menu="equity",
|
||||
symbol=symbol,
|
||||
provider=provider,
|
||||
start_date="2023-01-01",
|
||||
end_date="2023-12-31",
|
||||
)
|
||||
return data["stocks_data"]
|
||||
|
||||
|
||||
@@ -56,6 +64,8 @@ def get_crypto_data():
|
||||
menu="crypto",
|
||||
symbol=symbol,
|
||||
provider=provider,
|
||||
start_date="2023-01-01",
|
||||
end_date="2023-12-31",
|
||||
)
|
||||
return data["crypto_data"]
|
||||
|
||||
@@ -244,7 +254,7 @@ def test_quantitative_performance_sharpe_ratio(params, data_type):
|
||||
"data": "",
|
||||
"target": "close",
|
||||
"target_return": "0.5",
|
||||
"window": "275",
|
||||
"window": "150",
|
||||
"adjusted": "true",
|
||||
"index": "date",
|
||||
},
|
||||
|
||||
@@ -144,7 +144,7 @@ def stdev(data: List[Data], target: str) -> OBBject[List[Data]]:
|
||||
'obb.quantitative.stats.kurtosis(data=returns, target="close")',
|
||||
],
|
||||
)
|
||||
def kurtosis(data: List[Data], target) -> OBBject[List[Data]]:
|
||||
def kurtosis(data: List[Data], target: str) -> OBBject[List[Data]]:
|
||||
"""
|
||||
Calculate the rolling kurtosis of a target column.
|
||||
|
||||
@@ -154,10 +154,11 @@ def kurtosis(data: List[Data], target) -> OBBject[List[Data]]:
|
||||
This function helps in assessing the risk of outliers in financial returns or other time series data.
|
||||
|
||||
Parameters
|
||||
data: List[Data]
|
||||
The time series data as a list of data points.
|
||||
target: str
|
||||
The name of the column for which to calculate kurtosis.
|
||||
----------
|
||||
data: List[Data]
|
||||
The time series data as a list of data points.
|
||||
target: str
|
||||
The name of the column for which to calculate kurtosis.
|
||||
|
||||
Returns
|
||||
------
|
||||
|
||||
@@ -623,6 +623,8 @@ def vwap(
|
||||
The calculated data.
|
||||
"""
|
||||
df = basemodel_to_df(data, index=index)
|
||||
if index == "date":
|
||||
df.index = pd.to_datetime(df.index)
|
||||
df_target = get_target_columns(df, ["high", "low", "close", "volume"])
|
||||
df_vwap = pd.DataFrame(df_target.ta.vwap(anchor=anchor, offset=offset).dropna())
|
||||
|
||||
|
||||
@@ -708,6 +708,10 @@ class ROUTER_equity_fundamental(Container):
|
||||
Link to the filing. (provider: fmp)
|
||||
final_link : Optional[str]
|
||||
Link to the filing document. (provider: fmp)
|
||||
net_income_continuing_operations : Optional[float]
|
||||
Net Income (Continuing Operations) (provider: intrinio)
|
||||
net_income_discontinued_operations : Optional[float]
|
||||
Net Income (Discontinued Operations) (provider: intrinio)
|
||||
provision_for_loan_losses : Optional[float]
|
||||
Provision for Loan Losses (provider: intrinio)
|
||||
provision_for_credit_losses : Optional[float]
|
||||
@@ -726,10 +730,6 @@ class ROUTER_equity_fundamental(Container):
|
||||
Net Cash from Continuing Operating Activities (provider: intrinio)
|
||||
net_cash_from_discontinued_operating_activities : Optional[float]
|
||||
Net Cash from Discontinued Operating Activities (provider: intrinio)
|
||||
net_income_continuing_operations : Optional[float]
|
||||
Net Income (Continuing Operations) (provider: intrinio)
|
||||
net_income_discontinued_operations : Optional[float]
|
||||
Net Income (Discontinued Operations) (provider: intrinio)
|
||||
divestitures : Optional[float]
|
||||
Divestitures (provider: intrinio)
|
||||
sale_of_property_plant_and_equipment : Optional[float]
|
||||
|
||||
@@ -230,7 +230,10 @@ class IntrinioEquityHistoricalFetcher(
|
||||
**kwargs: Any,
|
||||
) -> List[IntrinioEquityHistoricalData]:
|
||||
"""Return the transformed data."""
|
||||
return [
|
||||
IntrinioEquityHistoricalData.model_validate(d)
|
||||
for d in sorted(data, key=lambda x: x["date"], reverse=False)
|
||||
]
|
||||
try:
|
||||
sorted_data = sorted(
|
||||
data, key=lambda x: x.get("date") or x.get("time"), reverse=False
|
||||
)
|
||||
except Exception:
|
||||
sorted_data = data
|
||||
return [IntrinioEquityHistoricalData.model_validate(d) for d in sorted_data]
|
||||
|
||||
@@ -4,7 +4,7 @@ import html
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from datetime import datetime, timedelta
|
||||
from itertools import repeat
|
||||
from typing import Any, Dict, List, Optional, Set, Union
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
import requests
|
||||
from openbb_core.provider.abstract.fetcher import Fetcher
|
||||
@@ -24,18 +24,16 @@ class NasdaqEconomicCalendarQueryParams(EconomicCalendarQueryParams):
|
||||
|
||||
__json_schema_extra__ = {"country": ["multiple_items_allowed"]}
|
||||
|
||||
country: Optional[Union[str, List[str]]] = Field(
|
||||
country: Optional[str] = Field(
|
||||
default=None,
|
||||
description="Country of the event",
|
||||
)
|
||||
|
||||
@field_validator("country", mode="before", check_fields=False)
|
||||
@classmethod
|
||||
def validate_country(cls, v: Union[str, List[str], Set[str]]):
|
||||
"""Validate the country input."""
|
||||
if isinstance(v, str):
|
||||
return v.lower().replace(" ", "_")
|
||||
return ",".join([country.lower().replace(" ", "_") for country in list(v)])
|
||||
def validate_country(cls, c: str): # pylint: disable=E0213
|
||||
"""Validate country."""
|
||||
return ",".join([v.lower() for v in c.replace(" ", "_").split(",")])
|
||||
|
||||
|
||||
class NasdaqEconomicCalendarData(EconomicCalendarData):
|
||||
|
||||
Reference in New Issue
Block a user