diff options
Diffstat (limited to 'openbb_platform/providers/yfinance/tests/test_yfinance_helpers.py')
-rw-r--r-- | openbb_platform/providers/yfinance/tests/test_yfinance_helpers.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/openbb_platform/providers/yfinance/tests/test_yfinance_helpers.py b/openbb_platform/providers/yfinance/tests/test_yfinance_helpers.py new file mode 100644 index 00000000000..9c8b13bca67 --- /dev/null +++ b/openbb_platform/providers/yfinance/tests/test_yfinance_helpers.py @@ -0,0 +1,34 @@ +"""Test yfinance helpers.""" + +import pandas as pd +import pytest + +from providers.yfinance.openbb_yfinance.utils.helpers import ( + df_transform_numbers, + get_futures_data, +) + +# pylint: disable=redefined-outer-name, unused-argument + +MOCK_FUTURES_DATA = pd.DataFrame({"Ticker": ["ES", "NQ"], "Exchange": ["CME", "CME"]}) + + +@pytest.fixture +def mock_futures_csv(monkeypatch): + """Mock pd.read_csv to return predefined futures data.""" + monkeypatch.setattr(pd, "read_csv", lambda *args, **kwargs: MOCK_FUTURES_DATA) + + +def test_get_futures_data(mock_futures_csv): + df = get_futures_data() + assert not df.empty + assert df.equals(MOCK_FUTURES_DATA) + + +def test_df_transform_numbers(): + data = pd.DataFrame( + {"Value": ["1M", "2.5B", "3T"], "% Change": ["1%", "-2%", "3.5%"]} + ) + transformed = df_transform_numbers(data, ["Value", "% Change"]) + assert transformed["Value"].equals(pd.Series([1e6, 2.5e9, 3e12])) + assert transformed["% Change"].equals(pd.Series([1.0, -2.0, 3.5])) |