Skip to content

Commit 55a9da2

Browse files
authored
test(marketdata): events 用例日期改为相对今天,消除到期爆炸 (#97)
test_events_parses_and_filters 把 notice_date 写死成 2026-07-12/07-10, 却用滚动窗口 since_days=30 取数。跨过窗口那天(2026-08-12,距 07-12 已 31 天) 两条 payload 全被过滤 → assert 0 == 2,0.10.2 的 release CI 因此中断。 改为按 date.today() 相对生成(recent=-2d / older=-4d),art_code 与 URL 断言随之动态化,断言语义(去重/排序/event_type/importance/symbols/source/url) 完全不变。 同类扫描:marketdata 其余用例的硬编码日期都是显式传入 date 参数(龙虎榜/北向/ 分红等),不依赖滚动窗口;test_news 的 since_hours 用例显式注入 now,均无此问题。
1 parent dfa1d6c commit 55a9da2

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

packages/marketdata/tests/test_events_vendor.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import date, timedelta
2+
13
import marketdata.vendors.events as ev
24
from marketdata.symbol import Symbol
35
from marketdata.types import EventItem
@@ -6,31 +8,39 @@
68
def test_events_parses_and_filters(monkeypatch):
79
# 东财 ann 响应结构与字段名以 src/collectors/events_collector.py 的 _parse_item 实际读取为准:
810
# data.list[].{art_code, title, notice_date, columns[].column_name, codes[].stock_code}
11+
#
12+
# 日期相对「今天」生成:since_days 窗口是滚动的,写死日期的用例会在跨过窗口那天
13+
# 突然全被过滤掉而失败(曾发生)。
14+
recent = date.today() - timedelta(days=2)
15+
older = date.today() - timedelta(days=4)
16+
recent_code = f"AN{recent:%Y%m%d}0002"
17+
older_code = f"AN{older:%Y%m%d}0001"
18+
919
payload = {
1020
"success": True,
1121
"data": {
1222
"list": [
1323
# 较新、"回购" -> event_type=repurchase, importance=2
1424
{
15-
"art_code": "AN202607120002",
25+
"art_code": recent_code,
1626
"title": "贵州茅台股份有限公司关于回购股份的公告",
17-
"notice_date": "2026-07-12 10:00:00",
27+
"notice_date": f"{recent:%Y-%m-%d} 10:00:00",
1828
"columns": [{"column_name": "临时公告"}],
1929
"codes": [{"stock_code": "600519"}],
2030
},
2131
# 较旧、"重大资产重组" -> event_type=restructuring, importance=3
2232
{
23-
"art_code": "AN202607100001",
33+
"art_code": older_code,
2434
"title": "贵州茅台股份有限公司关于重大资产重组的公告",
25-
"notice_date": "2026-07-10 09:00:00",
35+
"notice_date": f"{older:%Y-%m-%d} 09:00:00",
2636
"columns": [{"column_name": "重大事项"}],
2737
"codes": [{"stock_code": "600519"}],
2838
},
2939
# 与第一条重复的 art_code -> 应被去重
3040
{
31-
"art_code": "AN202607120002",
41+
"art_code": recent_code,
3242
"title": "贵州茅台股份有限公司关于回购股份的公告(重复)",
33-
"notice_date": "2026-07-12 10:00:00",
43+
"notice_date": f"{recent:%Y-%m-%d} 10:00:00",
3444
"columns": [{"column_name": "临时公告"}],
3545
"codes": [{"stock_code": "600519"}],
3646
},
@@ -47,15 +57,18 @@ def test_events_parses_and_filters(monkeypatch):
4757
# 去重生效:3 条输入 -> 2 条唯一 (source, external_id)
4858
assert len(out) == 2
4959

50-
# 排序:按 (publish_time, importance) 降序 -> 07-12 的回购公告排第一
51-
assert out[0].external_id == "AN202607120002"
60+
# 排序:按 (publish_time, importance) 降序 -> 较新的回购公告排第一
61+
assert out[0].external_id == recent_code
5262
assert out[0].event_type == "repurchase"
5363
assert out[0].importance == 2
5464
assert out[0].symbols == ["600519"]
5565
assert out[0].source == "eastmoney"
56-
assert out[0].url == "https://data.eastmoney.com/notices/detail/600519/AN202607120002.html"
66+
assert (
67+
out[0].url
68+
== f"https://data.eastmoney.com/notices/detail/600519/{recent_code}.html"
69+
)
5770

58-
assert out[1].external_id == "AN202607100001"
71+
assert out[1].external_id == older_code
5972
assert out[1].event_type == "restructuring"
6073
assert out[1].importance == 3
6174

0 commit comments

Comments
 (0)