fix(test): replace hardcoded dates with cn_today() in test_live_enriched_metadata

test_history_strategy_monitor_keeps_live_row_with_exclude_st_enabled used
date(2026,7,20) as the "today" value, but MonitorRuleEngine.evaluate()
calls cn_today() internally. The date mismatch caused the basic_filter
+ history filter to produce 0 rows, making the test fail 8 days after
it was written.

Also fixes test_live_enriched_cache_keeps_instrument_metadata_without_persisting_it
which used the same hardcoded date — would break on any future run.

Replace all hardcoded dates with cn_today() / cn_today()-timedelta(days=3)
so the tests are timeless.
This commit is contained in:
im47cn
2026-07-28 09:46:51 +08:00
parent d29ceed73d
commit 5f1c1cf0bb
+6 -5
View File
@@ -1,10 +1,11 @@
from __future__ import annotations
from datetime import date
from datetime import timedelta
from pathlib import Path
import polars as pl
from app.market_time import cn_today
from app.strategy.engine import StrategyEngine
from app.strategy.monitor import MonitorRuleEngine
from app.tickflow.repository import DataStore, KlineRepository
@@ -24,7 +25,7 @@ def _repo(tmp_path) -> KlineRepository:
def _live_row(symbol: str, close: float) -> pl.DataFrame:
return pl.DataFrame({
"symbol": [symbol],
"date": [date(2026, 7, 20)],
"date": [cn_today()],
"open": [close],
"high": [close],
"low": [close],
@@ -44,7 +45,7 @@ def test_live_enriched_cache_keeps_instrument_metadata_without_persisting_it(tmp
repo.merge_live_enriched_asset("stock", _live_row("000001.SZ", 12.0))
cached, cached_date = repo.get_enriched_latest()
assert cached_date == date(2026, 7, 20)
assert cached_date == cn_today()
assert cached.select("symbol", "name").sort("symbol").to_dicts() == [
{"symbol": "000001.SZ", "name": "平安银行"},
{"symbol": "600000.SH", "name": "浦发银行"},
@@ -53,7 +54,7 @@ def test_live_enriched_cache_keeps_instrument_metadata_without_persisting_it(tmp
assert cached["float_shares"].null_count() == 0
persisted = pl.read_parquet(
tmp_path / "kline_daily_enriched" / "date=2026-07-20" / "part.parquet"
tmp_path / "kline_daily_enriched" / f"date={cn_today().isoformat()}" / "part.parquet"
)
assert "name" not in persisted.columns
assert "total_shares" not in persisted.columns
@@ -84,7 +85,7 @@ def filter_history(df: pl.DataFrame, params: dict) -> pl.DataFrame:
)
repo.flush_live_enriched_asset("stock", live)
current, _ = repo.get_enriched_latest()
history = current.with_columns(pl.lit(date(2026, 7, 17)).alias("date"))
history = current.with_columns(pl.lit(cn_today() - timedelta(days=3)).alias("date"))
monitor = MonitorRuleEngine()
monitor.set_strategy_engine(StrategyEngine([Path(strategy_dir)]))