rebuild(stage-7): deliver ladder and sector rotation

This commit is contained in:
leefer
2026-07-30 03:28:24 +08:00
parent 31a53de890
commit a76d344a98
28 changed files with 1161 additions and 13 deletions
+46 -1
View File
@@ -314,6 +314,10 @@ def test_market_snapshot_units_and_yesterday_outcomes_are_deterministic() -> Non
)
assert snapshot["overview"]["amount"] == 500_000
assert snapshot["broken"][0]["distance_to_limit"] == 20
assert snapshot["ladders"][0]["level"] == 2
assert snapshot["ladders"][0]["stocks"][0]["code"] == "000001"
assert snapshot["sector_rotation"][0]["name"] == "测试行业"
assert snapshot["sector_rotation"][0]["delta"] == -4
assert [row["outcome"] for row in snapshot["yesterday_limits"]] == [
"晋级",
"炸板",
@@ -336,6 +340,43 @@ def test_market_snapshot_units_and_yesterday_outcomes_are_deterministic() -> Non
}
def test_sector_members_are_normalized_and_persistently_cached(tmp_path) -> None:
database = Database(tmp_path / "members.db")
MigrationRunner(database).upgrade(MIGRATIONS)
repository = MarketRepository()
provider = TushareProvider("test-token")
calls = 0
def members(*_):
nonlocal calls
calls += 1
return calculation_result(
[
{
"sector_code": "801082.SI",
"sector_name": "元件",
"ts_code": "002141.SZ",
"name": "贤丰控股",
"change": 3.2,
"open": 4.1,
"close": 4.3,
"amount": 123_000_000,
"quoted": True,
}
]
)
provider.sector_members = members
market = DataGateway(database, repository, (provider,), DataSourcePolicy())
first = market.sector_members("2026-07-29", "元件", "002141.SZ")
second = market.sector_members("2026-07-29", "元件", "002141.SZ")
assert calls == 1
assert first == second
assert first["items"][0]["code"] == "002141"
assert first["quoted_count"] == 1
def test_sentiment_has_all_weighted_components_and_extreme_risk_cap() -> None:
snapshot = {
"overview": {
@@ -401,7 +442,11 @@ def test_incomplete_daily_snapshot_is_rejected_without_overwriting(tmp_path) ->
"previous_limit_up": calculation_result([]),
"price_limits": calculation_result([]),
}
service = MarketSnapshotService(database, repository, provider)
service = MarketSnapshotService(
database,
repository,
DataGateway(database, repository, (provider,), DataSourcePolicy()),
)
with pytest.raises(SnapshotSyncError, match="覆盖率"):
service.sync("2026-07-29", datetime(2026, 7, 30, 16, tzinfo=SHANGHAI))
with database.read() as connection: