Initial commit of integrated agent system
This commit is contained in:
65
backend/tests/test_historical_price_manager.py
Normal file
65
backend/tests/test_historical_price_manager.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from unittest.mock import patch
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from backend.data.historical_price_manager import HistoricalPriceManager
|
||||
|
||||
|
||||
def test_preload_data_prefers_market_db():
|
||||
manager = HistoricalPriceManager()
|
||||
manager.subscribe(["AAPL"])
|
||||
|
||||
market_rows = [
|
||||
{
|
||||
"symbol": "AAPL",
|
||||
"date": "2026-03-09",
|
||||
"open": 100.0,
|
||||
"high": 103.0,
|
||||
"low": 99.0,
|
||||
"close": 102.0,
|
||||
"volume": 10_000,
|
||||
"vwap": 101.0,
|
||||
"transactions": 500,
|
||||
"source": "polygon",
|
||||
}
|
||||
]
|
||||
|
||||
with (
|
||||
patch.object(manager._market_store, "get_ohlc", return_value=market_rows),
|
||||
patch.object(manager._router, "load_local_price_frame") as load_csv,
|
||||
):
|
||||
manager.preload_data("2026-03-01", "2026-03-10")
|
||||
|
||||
load_csv.assert_not_called()
|
||||
assert "AAPL" in manager._price_cache
|
||||
assert float(manager._price_cache["AAPL"].iloc[0]["close"]) == 102.0
|
||||
|
||||
|
||||
def test_preload_data_falls_back_to_csv():
|
||||
manager = HistoricalPriceManager()
|
||||
manager.subscribe(["MSFT"])
|
||||
|
||||
csv_df = pd.DataFrame(
|
||||
{
|
||||
"time": ["2026-03-09"],
|
||||
"open": [200.0],
|
||||
"high": [205.0],
|
||||
"low": [198.0],
|
||||
"close": [204.0],
|
||||
"volume": [20_000],
|
||||
}
|
||||
)
|
||||
csv_df["time"] = pd.to_datetime(csv_df["time"])
|
||||
csv_df["Date"] = csv_df["time"]
|
||||
csv_df.set_index("Date", inplace=True)
|
||||
|
||||
with (
|
||||
patch.object(manager._market_store, "get_ohlc", return_value=[]),
|
||||
patch.object(manager._router, "load_local_price_frame", return_value=csv_df) as load_csv,
|
||||
):
|
||||
manager.preload_data("2026-03-01", "2026-03-10")
|
||||
|
||||
load_csv.assert_called_once_with("MSFT")
|
||||
assert "MSFT" in manager._price_cache
|
||||
assert float(manager._price_cache["MSFT"].iloc[0]["close"]) == 204.0
|
||||
Reference in New Issue
Block a user