Files
sanguo_vnpy_v2/tests/factor/test_observe.py
T

36 lines
1.2 KiB
Python

# tests/factor/test_observe.py
"""观察报告 TDD——spec §4.2 决议 E 成熟度门:未晋级只观察不告警不判死."""
from sanguo_factor.observe import MIN_COVERAGE, observe_factor
def test_red_when_no_records():
o = observe_factor([], as_of="2026-09-22")
assert o.status == "red" and o.last_seen is None
assert "无评估记录" in o.reasons[0]
def test_green_fresh_and_covered():
o = observe_factor([{"end": "2026-09-18", "count": 512}], as_of="2026-09-22")
assert o.status == "green" and o.reasons == ()
assert o.days_since == 4 and o.last_count == 512
def test_yellow_stale():
o = observe_factor([{"end": "2026-05-30", "count": 512}], as_of="2026-09-22")
assert o.status == "yellow" and any("新鲜" in r for r in o.reasons)
def test_yellow_thin_coverage():
o = observe_factor([{"end": "2026-09-18", "count": 120}], as_of="2026-09-22")
assert o.status == "yellow" and any("覆盖" in r for r in o.reasons)
def test_latest_record_wins():
recs = [{"end": "2026-03-01", "count": 900}, {"end": "2026-09-10", "count": 50}]
o = observe_factor(recs, as_of="2026-09-22")
assert o.last_seen == "2026-09-10" and o.last_count == 50
def test_min_coverage_constant():
assert MIN_COVERAGE == 300