"""Verify API facts against independently calculated persisted real data.""" import json from decimal import Decimal from pathlib import Path from urllib.request import urlopen root='http://127.0.0.1:8016/api/v1/sector-radar/' d=json.load(urlopen(root+'sectors/concept/BK1147.DC/detail?trade_date=2026-09-04')) assert d['status']=='success' assert len(d['members'])==14 assert Decimal(d['pct_change'])==Decimal('1.82') assert sum(Decimal(m['net_amount_yuan']) for m in d['members'])==Decimal('485456500') assert sum(Decimal(m['active_buy_net_amount_yuan']) for m in d['members'])==Decimal('-255455700') assert Decimal(d['summary']['amount']['metric_value'])==Decimal('4.854565') # Storage uses 12 fractional digits for persisted metric observations. assert abs(Decimal(d['summary']['ratio']['metric_value'])-Decimal('0.18560945649159168662'))