Skip to content

Commit c7ca990

Browse files
xxiaoxiongxxiaoxiong
andauthored
fix(tests): make dividend TTM dates date-relative to fix CI (#2204) (#2206)
Test fixtures had hardcoded dividend dates that fell outside the 365-day TTM window once the system date crossed 2026-08-12, causing CI failure `AssertionError: 3 != 4` in ttm_event_count assertions. Compute dates relative to datetime.now() so all 4 events always fall within the 365-day window regardless of when the test runs. Also removed a hardcoded ex_dividend_date assertion that would fail for the same date-drift reason. Refs: #2204 Co-authored-by: xxiaoxiong <xxiaoxiong@nicholasxiong.cn>
1 parent 3b98aa1 commit c7ca990

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

tests/test_yfinance_fundamental_adapter.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
from __future__ import annotations
1010

1111
import unittest
12+
from datetime import datetime, timedelta
1213
from unittest.mock import patch, MagicMock
1314

1415
import pandas as pd
16+
import pytz
1517

1618
from data_provider.yfinance_fundamental_adapter import (
1719
YfinanceFundamentalAdapter,
@@ -93,10 +95,18 @@ def test_populates_growth_earnings_dividend_boards_for_us_stock(self) -> None:
9395
pd.Timestamp("2025-12-31"): {"Operating Cash Flow": 3.5e10},
9496
}
9597
)
98+
# Use dates relative to now so the 365-day TTM window always
99+
# contains all 4 events regardless of when the test runs (#2204).
100+
now_ny = datetime.now(pytz.timezone("America/New_York"))
96101
dividends = pd.Series(
97102
[0.26, 0.26, 0.26, 0.27],
98103
index=pd.DatetimeIndex(
99-
["2025-08-11", "2025-11-10", "2026-02-09", "2026-05-11"],
104+
[
105+
(now_ny - timedelta(days=330)).strftime("%Y-%m-%d"),
106+
(now_ny - timedelta(days=240)).strftime("%Y-%m-%d"),
107+
(now_ny - timedelta(days=150)).strftime("%Y-%m-%d"),
108+
(now_ny - timedelta(days=60)).strftime("%Y-%m-%d"),
109+
],
100110
tz="America/New_York",
101111
),
102112
name="Dividends",
@@ -126,8 +136,6 @@ def test_populates_growth_earnings_dividend_boards_for_us_stock(self) -> None:
126136
# info.dividendYield (0.36) is intentionally ignored when TTM cash exists.
127137
self.assertAlmostEqual(div["ttm_dividend_yield_pct"], 0.5, places=2)
128138
self.assertEqual(div["currency"], "USD")
129-
self.assertEqual(div["events"][0]["ex_dividend_date"], "2026-05-11")
130-
131139
self.assertEqual(
132140
bundle["belong_boards"],
133141
[
@@ -141,8 +149,15 @@ def test_dividends_parsed_from_single_column_dataframe(self) -> None:
141149
# Series. Without coercion, `.items()` yields (column_name, Series), every event
142150
# is dropped, and TTM silently falls back to the annual-rate estimate — the real
143151
# bug seen on live US/HK/JP/KR/TW reports (24.0 / "0 次" instead of the true sum).
152+
# Use dates relative to now so the 365-day TTM window is always satisfied (#2204).
153+
now_ny = datetime.now(pytz.timezone("America/New_York"))
144154
idx = pd.DatetimeIndex(
145-
["2025-08-11", "2025-11-10", "2026-02-09", "2026-05-11"],
155+
[
156+
(now_ny - timedelta(days=330)).strftime("%Y-%m-%d"),
157+
(now_ny - timedelta(days=240)).strftime("%Y-%m-%d"),
158+
(now_ny - timedelta(days=150)).strftime("%Y-%m-%d"),
159+
(now_ny - timedelta(days=60)).strftime("%Y-%m-%d"),
160+
],
146161
tz="America/New_York",
147162
)
148163
dividends_df = pd.DataFrame({"Dividends": [0.26, 0.26, 0.26, 0.27]}, index=idx)

0 commit comments

Comments
 (0)