1+ from datetime import date , timedelta
2+
13import marketdata .vendors .events as ev
24from marketdata .symbol import Symbol
35from marketdata .types import EventItem
68def 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