78 lines
4.4 KiB
Python
78 lines
4.4 KiB
Python
|
|
import copy
|
||
|
|
import datetime as dt
|
||
|
|
import tempfile
|
||
|
|
import unittest
|
||
|
|
from unittest.mock import patch
|
||
|
|
import test_api_support
|
||
|
|
import card
|
||
|
|
import config
|
||
|
|
import plan
|
||
|
|
import plan_inputs
|
||
|
|
|
||
|
|
|
||
|
|
class AdmissionTests(unittest.TestCase):
|
||
|
|
def test_rule_revision_uses_new_cutoff_and_preserves_morning_version(self):
|
||
|
|
import plan_refresh, plan_versions as pv
|
||
|
|
with tempfile.TemporaryDirectory() as root:
|
||
|
|
now=dt.datetime.fromisoformat('2026-11-10T12:00:00+08:00')
|
||
|
|
old={'date':'2026-11-09','main':[{'code':'SH600001','verdict':'仅展示'}],'observe':[]}
|
||
|
|
inputs={'records':{},'user_candidates':[],'market':{},'regime':None}
|
||
|
|
first=pv.publish(root,old,inputs,{'CARD_ACCUM_CONFIRM_REQUIRED':False},
|
||
|
|
cutoff_at='2026-11-10T07:10:00+08:00',reason='晨版')
|
||
|
|
def collect(*a,**k):
|
||
|
|
self.assertTrue(plan.config.CARD_CONSENSUS_ADMISSION_ENABLED)
|
||
|
|
return {**copy.deepcopy(old),'_full':{'main':[{'code':'SH600001','verdict':'候选'}],'observe':[]}}
|
||
|
|
with patch.object(config,'PLAN_SNAPSHOT_DIR',root), \
|
||
|
|
patch.object(config,'CARD_CONSENSUS_ADMISSION_ENABLED',True), \
|
||
|
|
patch.object(config,'CARD_ACCUM_CONFIRM_REQUIRED',False), \
|
||
|
|
patch.object(plan_refresh,'in_window',return_value=True), \
|
||
|
|
patch.object(plan,'collect',side_effect=collect),patch.object(plan,'write_published_md'):
|
||
|
|
self.assertEqual(plan_refresh.refresh(now=now)['status'],'published')
|
||
|
|
newest=pv.load(root)
|
||
|
|
self.assertEqual(newest['decision']['reason'],'选股方向统一交由三源合议')
|
||
|
|
self.assertEqual(newest['decision']['cutoff_at'],now.isoformat())
|
||
|
|
self.assertEqual(pv.load(root,morning=True),first)
|
||
|
|
self.assertEqual(plan_refresh.refresh(now=now)['status'],'unchanged')
|
||
|
|
|
||
|
|
def test_unpointed_and_old_direction_reach_consensus_without_faking_evidence(self):
|
||
|
|
for signal in ['SELL','AVOID','DROPPED','WATCH']:
|
||
|
|
result=card.judge(dict(pointed=False,covered=True,upside=.2,pct0=4,
|
||
|
|
accum_state='高位派发',accum_age=0,y_signal=signal),consensus_admission=True)
|
||
|
|
self.assertEqual(result['verdict'],'候选')
|
||
|
|
self.assertFalse(result['gates']['pointed'])
|
||
|
|
self.assertNotIn('pointed',result['failed_gates'])
|
||
|
|
self.assertEqual(result['risk'],[])
|
||
|
|
self.assertIn('资金在高位派发',result['reference_risk'])
|
||
|
|
self.assertNotIn('所在环节当日没有被传导指向',str(result))
|
||
|
|
|
||
|
|
def test_security_coverage_valuation_and_stale_snapshot_still_block(self):
|
||
|
|
ev=dict(pointed=False,covered=True,upside=.2,pct0=4,accum_state='')
|
||
|
|
for changes in [{'risk_name':True},{'covered':False},{'upside':-.1},{'stale_snapshot':True}]:
|
||
|
|
self.assertEqual(card.judge(dict(ev,**changes),consensus_admission=True)['verdict'],'仅展示')
|
||
|
|
self.assertEqual(card.judge(ev,consensus_admission=True,company_review={'overall':'差','age_days':1})['verdict'],'关注')
|
||
|
|
|
||
|
|
def test_old_frozen_config_does_not_inherit_new_environment_switch(self):
|
||
|
|
with patch.object(config,'CARD_CONSENSUS_ADMISSION_ENABLED',True):
|
||
|
|
bundle=plan_inputs.Bundle(records={},params={})
|
||
|
|
with bundle.use():
|
||
|
|
self.assertFalse(plan.config.CARD_CONSENSUS_ADMISSION_ENABLED)
|
||
|
|
|
||
|
|
def test_manual_rows_survive_snapshot_top_only_for_opted_in_consumer(self):
|
||
|
|
import plan_versions
|
||
|
|
a=dict(code='SH600001',score=200,rank=1,research_rank=1)
|
||
|
|
b=dict(code='SZ300133',score=100,rank=100,research_rank=100,
|
||
|
|
user_candidate={'id':'x','expires_on':'2099-01-01'},user_required=True)
|
||
|
|
snap={'date':'2026-11-09','main':[a,b],'observe':[], 'shown_params':{},
|
||
|
|
'decision':{'id':'test'},'rank_axis':'quality'}
|
||
|
|
before=copy.deepcopy(snap)
|
||
|
|
with patch.object(plan_versions,'load',return_value=snap), \
|
||
|
|
patch.object(plan_versions,'health',return_value={}):
|
||
|
|
yes=plan.from_snapshot(date="2026-11-09",top=1,include_user_candidates=True)
|
||
|
|
no=plan.from_snapshot(date="2026-11-09",top=1,include_user_candidates=False)
|
||
|
|
self.assertEqual([r['code'] for r in yes['main']],['SH600001','SZ300133'])
|
||
|
|
self.assertEqual([r['code'] for r in no['main']],['SH600001'])
|
||
|
|
self.assertEqual(snap,before)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':unittest.main()
|