75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
import pytest
|
|
|
|
from app.services.backtesting.fixture_source import (
|
|
SEEDED_GLD_2024_FIXTURE_HISTORY,
|
|
SharedHistoricalFixtureSource,
|
|
WindowPolicy,
|
|
)
|
|
from app.services.backtesting.ui_service import BacktestPageService
|
|
from app.services.event_comparison_ui import EventComparisonPageService
|
|
|
|
|
|
def test_shared_fixture_source_exact_window_requires_seeded_bounds() -> None:
|
|
source = SharedHistoricalFixtureSource(
|
|
feature_label="BT-001A",
|
|
supported_symbol="GLD",
|
|
history=SEEDED_GLD_2024_FIXTURE_HISTORY,
|
|
window_policy=WindowPolicy.EXACT,
|
|
)
|
|
|
|
rows = source.load_daily_closes("GLD", date(2024, 1, 2), date(2024, 1, 8))
|
|
|
|
assert [row.date.isoformat() for row in rows] == [
|
|
"2024-01-02",
|
|
"2024-01-03",
|
|
"2024-01-04",
|
|
"2024-01-05",
|
|
"2024-01-08",
|
|
]
|
|
|
|
with pytest.raises(ValueError, match="seeded 2024-01-02 through 2024-01-08 window"):
|
|
source.load_daily_closes("GLD", date(2024, 1, 3), date(2024, 1, 8))
|
|
|
|
|
|
def test_shared_fixture_source_bounded_window_allows_subranges_but_fails_closed_outside_seeded_bounds() -> None:
|
|
source = SharedHistoricalFixtureSource(
|
|
feature_label="BT-003A",
|
|
supported_symbol="GLD",
|
|
history=SEEDED_GLD_2024_FIXTURE_HISTORY,
|
|
window_policy=WindowPolicy.BOUNDED,
|
|
)
|
|
|
|
rows = source.load_daily_closes("GLD", date(2024, 1, 3), date(2024, 1, 5))
|
|
|
|
assert [row.date.isoformat() for row in rows] == ["2024-01-03", "2024-01-04", "2024-01-05"]
|
|
|
|
with pytest.raises(ValueError, match="seeded 2024-01-02 through 2024-01-08 window"):
|
|
source.load_daily_closes("GLD", date(2024, 1, 1), date(2024, 1, 8))
|
|
|
|
with pytest.raises(ValueError, match="start_date must be on or before end_date"):
|
|
source.load_daily_closes("GLD", date(2024, 1, 5), date(2024, 1, 3))
|
|
|
|
|
|
def test_backtest_page_service_uses_shared_exact_fixture_source() -> None:
|
|
service = BacktestPageService()
|
|
|
|
source = service.backtest_service.provider.source
|
|
|
|
assert isinstance(source, SharedHistoricalFixtureSource)
|
|
assert source.feature_label == "BT-001A"
|
|
assert source.window_policy is WindowPolicy.EXACT
|
|
|
|
|
|
def test_event_comparison_page_service_uses_shared_bounded_fixture_source() -> None:
|
|
service = EventComparisonPageService()
|
|
|
|
source = service.comparison_service.provider.source
|
|
|
|
assert isinstance(source, SharedHistoricalFixtureSource)
|
|
assert source.feature_label == "BT-003A"
|
|
assert source.window_policy is WindowPolicy.BOUNDED
|