支持冻结输入切换质地排序并统一研究池来源(台账083)
This commit is contained in:
parent
10968f7fc7
commit
dabb96b56b
|
|
@ -862,3 +862,13 @@
|
||||||
- **依据。** 桥79项联合及六组原脚本、PMS48批候选镜像禁网回归通过。实际175条可查看研究中零家通过资格,丽珠与海尔仍证据不足。浏览器核对全部记录及无建仓按钮。
|
- **依据。** 桥79项联合及六组原脚本、PMS48批候选镜像禁网回归通过。实际175条可查看研究中零家通过资格,丽珠与海尔仍证据不足。浏览器核对全部记录及无建仓按钮。
|
||||||
- **预期。** 研究达到条件后,由用户主动准备建议并人工采纳。保留原交易规则。部署前后19参数、23持仓、322批次一致,108指令仅三条正常更新时间。旧145份计划文件哈希不变。
|
- **预期。** 研究达到条件后,由用户主动准备建议并人工采纳。保留原交易规则。部署前后19参数、23持仓、322批次一致,108指令仅三条正常更新时间。旧145份计划文件哈希不变。
|
||||||
- **复核日期。** 10:51服务健康、QMT在线、对账无差异。137恢复后10:50正常成功15秒。完整自然高股息采纳与成交尚未发生,单列待判收,不制造交易。详见四仓同日交接。
|
- **复核日期。** 10:51服务健康、QMT在线、对账无差异。137恢复后10:50正常成功15秒。完整自然高股息采纳与成交尚未发生,单列待判收,不制造交易。详见四仓同日交接。
|
||||||
|
|
||||||
|
## 083 · 2026-10-26 · 完成质地排序与 PMS 准入的统一切换
|
||||||
|
|
||||||
|
用户授权全权完成此前未上线的新排序。采用已定的公司质地优先次序,PMS 取消传导档位白名单,不新造加权分;保留被指向门槛、判决、风险、研判与组合约束。原 9 月“两档白名单”的待执行安排由本次取消档位过滤取代。只部署 155 模拟链路,不部署 188 真实 PMS。
|
||||||
|
|
||||||
|
桥新增 plan-rank 显式入口。默认只预览;发布必须核对预览版本和有效配置,禁止重写历史决策日,禁止在研究修订未完成时切换。使用原冻结输入重放,只允许排序字段变化,原分数、判决、风险和研究内容变化即拒绝。发布只追加修订版,保留晨版及所有旧版本;普通五分钟修订继续沿用新版本冻结的排序参数。
|
||||||
|
|
||||||
|
研究池改为读取已发布快照,避免现场重装配另一套研究和排序,并记录决策版本与研究名次。PMS 命令升仓继承 selection_rank,用户点名优先,已在计划中的点名票也不丢优先级,黑名单及持仓排除保持。
|
||||||
|
|
||||||
|
开发机 PMS 配置隔离、禁网全量 50 批通过,新增 11 例。155 临时只读源码目录、无业务配置的断网容器通过桥 54 组契约测试,新增 9 组。真实冻结输入断网重放通过资格与研究不变检查。此处记录代码交付;服务器重建、参数切换、真实消费及研究池覆盖的判收另补,不以测试代替上线。
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
"""显式切换当天计划排序。冻结输入不变,只追加版本,不调用外部来源。"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import copy
|
||||||
|
import datetime as dt
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
import config
|
||||||
|
import plan
|
||||||
|
import plan_inputs as pi
|
||||||
|
import plan_versions as pv
|
||||||
|
|
||||||
|
BJ = ZoneInfo('Asia/Shanghai')
|
||||||
|
PROTECTED = ('score', 'score_adj', 'tier', 'verdict', 'reasons', 'missing', 'risk',
|
||||||
|
'pointed', 'company_review', 'logic_state', 'heat', 'upside', 'evidence')
|
||||||
|
|
||||||
|
|
||||||
|
def prepare(envelope, axis):
|
||||||
|
"""只重排已有输入;任何资格或研究内容漂移都拒绝发布。"""
|
||||||
|
if axis not in ('quality', 'transmission'):
|
||||||
|
raise ValueError('排序轴无效')
|
||||||
|
old = envelope['plan']
|
||||||
|
params = dict(envelope['params'], PLAN_RANK_AXIS=axis, CARD_SORT_BY_QUALITY=axis == 'quality')
|
||||||
|
inputs = copy.deepcopy(envelope['inputs'])
|
||||||
|
# 保留原输入截止时刻,发布时刻由 switch 单独记录。
|
||||||
|
bundle = pi.Bundle(records=inputs['records'], params=params,
|
||||||
|
cutoff_at=old['decision']['cutoff_at'])
|
||||||
|
shown = old.get('shown_params') or {'top': 20, 'obs_top': 10, 'theme_cap': 5}
|
||||||
|
with bundle.use():
|
||||||
|
data = plan.collect(old['date'], **shown)
|
||||||
|
full = data.pop('_full')
|
||||||
|
for bucket in ('main', 'observe'):
|
||||||
|
before = {r['code']: r for r in old[bucket]}
|
||||||
|
after = {r['code']: r for r in full[bucket]}
|
||||||
|
if len(after) != len(full[bucket]) or before.keys() != after.keys():
|
||||||
|
raise ValueError('排序切换不得增删股票')
|
||||||
|
for code, row in before.items():
|
||||||
|
changed = [k for k in PROTECTED if row.get(k) != after[code].get(k)]
|
||||||
|
if changed:
|
||||||
|
raise ValueError(f'冻结输入重放改变资格或研究: {code} {changed}')
|
||||||
|
data.update(main_shown=data['main'], observe_shown=data['observe'], shown_params=shown,
|
||||||
|
main=full['main'], observe=full['observe'], market=inputs.get('market'),
|
||||||
|
regime=inputs.get('regime'))
|
||||||
|
return data, inputs, params
|
||||||
|
|
||||||
|
|
||||||
|
def switch(day=None, *, axis='quality', apply=False, expected_decision_id=None, now=None):
|
||||||
|
"""默认只预览;写入要求指定被复核的版本,且运行配置与目标一致。"""
|
||||||
|
now = now or dt.datetime.now(dt.timezone.utc)
|
||||||
|
root = config.PLAN_SNAPSHOT_DIR
|
||||||
|
with pv.writer(root):
|
||||||
|
old = pv.load(root, day)
|
||||||
|
source = old.get('decision') or {}
|
||||||
|
if not source.get('id'):
|
||||||
|
raise ValueError('旧格式计划不得覆盖')
|
||||||
|
morning = pv.load(root, old['date'], morning=True)
|
||||||
|
decision_day = dt.datetime.fromisoformat(morning['decision']['cutoff_at']).astimezone(BJ).date()
|
||||||
|
if decision_day != now.astimezone(BJ).date():
|
||||||
|
raise ValueError('只能切换当前决策日,历史计划只读')
|
||||||
|
state = pv.health(root, old['date'])
|
||||||
|
if state.get('pending_codes') or state.get('error'):
|
||||||
|
raise ValueError('研究修订尚未完成,暂不切换排序')
|
||||||
|
if apply:
|
||||||
|
if not expected_decision_id or source['id'] != expected_decision_id:
|
||||||
|
raise ValueError('计划版本已变化,重新预览后再切换')
|
||||||
|
if config.PLAN_RANK_AXIS != axis or config.CARD_SORT_BY_QUALITY != (axis == 'quality'):
|
||||||
|
raise ValueError('运行配置与目标排序不一致')
|
||||||
|
env = pv.envelope(root, source['id'])
|
||||||
|
data, inputs, params = prepare(env, axis)
|
||||||
|
result = {'status': 'preview', 'source_decision': source['id'], 'axis': axis,
|
||||||
|
'main_count': len(data['main']), 'observe_count': len(data['observe']),
|
||||||
|
'input_hash': pv.digest(inputs), 'params_hash': pv.digest(params),
|
||||||
|
'first20': [{k: r.get(k) for k in ('code', 'name', 'rank', 'tier', 'quality_band')}
|
||||||
|
for r in data['main'][:20]]}
|
||||||
|
if apply:
|
||||||
|
published = pv.publish(root, data, inputs, params, cutoff_at=now.isoformat(),
|
||||||
|
reason='用户授权切换选股排序:' + axis)
|
||||||
|
plan.write_published_md(published)
|
||||||
|
result.update(status='unchanged' if published['decision']['id'] == source['id'] else 'published',
|
||||||
|
decision=published['decision'])
|
||||||
|
return result
|
||||||
22
pool.py
22
pool.py
|
|
@ -7,7 +7,7 @@
|
||||||
这就是「提前计算为主」:不新造任何推理步骤,把票放进池子,已有的夜间推理自然完成预计算。
|
这就是「提前计算为主」:不新造任何推理步骤,把票放进池子,已有的夜间推理自然完成预计算。
|
||||||
|
|
||||||
入池、留池、出池的规则(用户拍板,decide() 的注释里逐条对应):
|
入池、留池、出池的规则(用户拍板,decide() 的注释里逐条对应):
|
||||||
入池 = 当日计划(强传导主榜前 N,与 PMS 候选同口径) ∪ 当前持仓
|
入池 = 已发布计划中按有效名次选出的研究对象 ∪ 当前持仓
|
||||||
留池 = 旧成员既不在计划也无持仓、但形态未恶化的,留下继续接受每晚分析
|
留池 = 旧成员既不在计划也无持仓、但形态未恶化的,留下继续接受每晚分析
|
||||||
——榜单是按条数截断过的,掉榜不等于变坏
|
——榜单是按条数截断过的,掉榜不等于变坏
|
||||||
出池 = 无持仓、不在计划、且形态已恶化(决策系统最新定性 SELL / AVOID / DROPPED)
|
出池 = 无持仓、不在计划、且形态已恶化(决策系统最新定性 SELL / AVOID / DROPPED)
|
||||||
|
|
@ -322,16 +322,14 @@ def _kick_bionic_scan() -> str:
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
def push(date: str | None = None, top: int | None = None,
|
def push(date: str | None = None, top: int | None = None,
|
||||||
dry_run: bool = False, kick: bool = True) -> dict:
|
dry_run: bool = False, kick: bool = True) -> dict:
|
||||||
# 1. 当日计划(与 /plan 同一段装配代码)→ 先筛档位、再按绝对得分截断。
|
# 1. 与 /plan 共用已发布的完整计划。rank 源按研究名次取被指向的前 top;
|
||||||
# 次序要紧(2026-08-17 修):原来是"全档位取前 top、再筛强传导"——排进 top 的
|
# 旧 tier/candidate 源仍遵守显式配置,主题限额由 POOL_THEME_CAP 决定。
|
||||||
# 弱/无传导票把 top 之外的强传导票挤掉了,与 PMS 候选的"先筛强传导再截断"分叉,
|
|
||||||
# 两边看到的候选不是同一批。所以这里向 collect 要一个宽池子(top 的十倍、至少
|
|
||||||
# 二百,全在打分池规模之内),先过档位白名单,最后取前 top。
|
|
||||||
# 主题限额默认 0(config.POOL_THEME_CAP,2026-08-17 拍板:分散不由选层做,
|
|
||||||
# 组合分散归 PMS 行业闸;配非零值即应急回退)。
|
|
||||||
top = top or config.POOL_TOP
|
top = top or config.POOL_TOP
|
||||||
data = plan.collect(date, top=max(top * 10, 200), obs_top=0,
|
# 入池必须和 PMS 消费同一已发布版本;禁止现场重装配另一份研究与次序。
|
||||||
theme_cap=config.POOL_THEME_CAP)
|
data = plan.from_snapshot(date, top=max(top * 10, 200), obs_top=0,
|
||||||
|
theme_cap=config.POOL_THEME_CAP)
|
||||||
|
if (data.get('refresh_status') or {}).get('pending_codes') or (data.get('refresh_status') or {}).get('error'):
|
||||||
|
raise RuntimeError('计划修订尚未完成,研究池保持原样')
|
||||||
tiers = config.POOL_TIERS
|
tiers = config.POOL_TIERS
|
||||||
ds = data["date"]
|
ds = data["date"]
|
||||||
# 选行抽成纯函数(2026-09-17):rank 源取新序里被指向的前 top,tier/candidate 逐字保留。
|
# 选行抽成纯函数(2026-09-17):rank 源取新序里被指向的前 top,tier/candidate 逐字保留。
|
||||||
|
|
@ -414,6 +412,8 @@ def push(date: str | None = None, top: int | None = None,
|
||||||
for r in plan_rows:
|
for r in plan_rows:
|
||||||
ctx[r["code"]] = {**strategy_context_entry(r, ds, seg_ratio),
|
ctx[r["code"]] = {**strategy_context_entry(r, ds, seg_ratio),
|
||||||
"source": r.get("_pool_source"),
|
"source": r.get("_pool_source"),
|
||||||
|
"decision_id": (data.get('decision') or {}).get('id'),
|
||||||
|
"research_rank": r.get('research_rank'),
|
||||||
"plan_version": data.get("plan_version")}
|
"plan_version": data.get("plan_version")}
|
||||||
for c in d["retained_holdings"]:
|
for c in d["retained_holdings"]:
|
||||||
ctx.setdefault(c, {"factor_code": "akg_score", "note": "持仓保留"})
|
ctx.setdefault(c, {"factor_code": "akg_score", "note": "持仓保留"})
|
||||||
|
|
@ -423,7 +423,7 @@ def push(date: str | None = None, top: int | None = None,
|
||||||
{"group_code": config.POOL_GROUP_CODE, "org_id": config.POOL_ORG_ID},
|
{"group_code": config.POOL_GROUP_CODE, "org_id": config.POOL_ORG_ID},
|
||||||
{"$set": {"group_name": config.POOL_GROUP_NAME, "pool_type": config.POOL_TYPE,
|
{"$set": {"group_name": config.POOL_GROUP_NAME, "pool_type": config.POOL_TYPE,
|
||||||
"is_public": False,
|
"is_public": False,
|
||||||
"description": "akg-factor-bridge 每日选股计划池:当日计划(强传导主榜) + "
|
"description": "akg-factor-bridge 每日选股计划池:已发布计划的研究对象 + "
|
||||||
"持仓保留 + 留池观察。决策系统每晚认知扫描按本组产出结论,"
|
"持仓保留 + 留池观察。决策系统每晚认知扫描按本组产出结论,"
|
||||||
"供 PMS 参考位/择时/研判使用。规则见 akg-factor-bridge/"
|
"供 PMS 参考位/择时/研判使用。规则见 akg-factor-bridge/"
|
||||||
"docs/选股计划入池_对接说明.md",
|
"docs/选股计划入池_对接说明.md",
|
||||||
|
|
|
||||||
10
run.py
10
run.py
|
|
@ -182,6 +182,11 @@ def main():
|
||||||
ra = sub.add_parser("regime-append") # 08:45 环境追加(写当日计划快照的 regime 段)
|
ra = sub.add_parser("regime-append") # 08:45 环境追加(写当日计划快照的 regime 段)
|
||||||
rf = sub.add_parser('plan-refresh')
|
rf = sub.add_parser('plan-refresh')
|
||||||
rf.add_argument('--date', help='已发布计划的数据日,默认最新;仍检查交易日与时窗')
|
rf.add_argument('--date', help='已发布计划的数据日,默认最新;仍检查交易日与时窗')
|
||||||
|
rk = sub.add_parser('plan-rank', help='预览或显式发布当天的排序切换,冻结输入不变')
|
||||||
|
rk.add_argument('--date')
|
||||||
|
rk.add_argument('--axis', choices=('quality', 'transmission'), default='quality')
|
||||||
|
rk.add_argument('--apply', action='store_true')
|
||||||
|
rk.add_argument('--expected-decision-id', help='写入前必须与预览版本一致')
|
||||||
ra.add_argument("--date", help="默认取 score 表最新日(与 plan 同口径)")
|
ra.add_argument("--date", help="默认取 score 表最新日(与 plan 同口径)")
|
||||||
jg = sub.add_parser("judgement-snapshot") # 日频行业观点快照(只写不判,攒版本史)
|
jg = sub.add_parser("judgement-snapshot") # 日频行业观点快照(只写不判,攒版本史)
|
||||||
jg.add_argument("--date", help="计划日,默认今天;补写过去的日期会让版本史失真,会有提示")
|
jg.add_argument("--date", help="计划日,默认今天;补写过去的日期会让版本史失真,会有提示")
|
||||||
|
|
@ -237,6 +242,11 @@ def main():
|
||||||
print(result)
|
print(result)
|
||||||
if result['status'] in ('no_morning', 'no_morning_today'):
|
if result['status'] in ('no_morning', 'no_morning_today'):
|
||||||
raise SystemExit('今日完整晨版缺失,保留上次版本,修订未执行。')
|
raise SystemExit('今日完整晨版缺失,保留上次版本,修订未执行。')
|
||||||
|
elif a.cmd == 'plan-rank':
|
||||||
|
import json
|
||||||
|
import plan_rank_switch
|
||||||
|
print(json.dumps(plan_rank_switch.switch(a.date, axis=a.axis, apply=a.apply,
|
||||||
|
expected_decision_id=a.expected_decision_id), ensure_ascii=False))
|
||||||
elif a.cmd == "judgement-snapshot":
|
elif a.cmd == "judgement-snapshot":
|
||||||
import judgement
|
import judgement
|
||||||
judgement.snapshot(a.date)
|
judgement.snapshot(a.date)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ import test_api_support # noqa: F401
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
for name in ('test_plan_versions', 'test_plan_reviews_live', 'test_plan_review_source', 'test_plan_stock_check'):
|
for name in ('test_plan_versions', 'test_plan_reviews_live', 'test_plan_review_source', 'test_plan_stock_check',
|
||||||
|
'test_plan_rank_switch'):
|
||||||
suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(importlib.import_module(name)))
|
suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(importlib.import_module(name)))
|
||||||
for name in ('test_plan_cache', 'test_plan_snapshot', 'test_plan_rank_axis',
|
for name in ('test_plan_cache', 'test_plan_snapshot', 'test_plan_rank_axis',
|
||||||
'test_plan_quality_rank', 'test_plan_verdict', 'test_plan_logic_state',
|
'test_plan_quality_rank', 'test_plan_verdict', 'test_plan_logic_state',
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,140 @@
|
||||||
|
"""排序切换的发布边界和研究池同源回归。全部来源使用替身。"""
|
||||||
|
import copy
|
||||||
|
import datetime as dt
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import config
|
||||||
|
import plan
|
||||||
|
import plan_inputs as pi
|
||||||
|
import plan_versions as pv
|
||||||
|
import plan_rank_switch as rs
|
||||||
|
import pool
|
||||||
|
|
||||||
|
DAY = '2026-10-23'
|
||||||
|
NOW = dt.datetime.fromisoformat('2026-10-26T14:00:00+08:00')
|
||||||
|
|
||||||
|
|
||||||
|
class RankSwitchTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.tmp = tempfile.TemporaryDirectory()
|
||||||
|
self.addCleanup(self.tmp.cleanup)
|
||||||
|
self.root = self.tmp.name
|
||||||
|
p = patch.object(config, 'PLAN_SNAPSHOT_DIR', self.root)
|
||||||
|
p.start()
|
||||||
|
self.addCleanup(p.stop)
|
||||||
|
rows = [{'code': 'SH600001', 'name': '甲', 'score': 240, 'tier': '强传导',
|
||||||
|
'rank': 1, 'quality_band': 0, 'rank_axis': 'transmission', 'verdict': '关注'},
|
||||||
|
{'code': 'SH600002', 'name': '乙', 'score': 220, 'tier': '弱传导',
|
||||||
|
'rank': 2, 'quality_band': 3, 'rank_axis': 'transmission', 'verdict': '候选'}]
|
||||||
|
with pv.writer(self.root):
|
||||||
|
self.old = pv.publish(self.root, {'date': DAY, 'plan_version': 'test', 'main': rows,
|
||||||
|
'observe': [], 'candidates': [], 'watch': []}, {'records': {}, 'market': {}, 'regime': None},
|
||||||
|
{'PLAN_RANK_AXIS': 'transmission', 'CARD_SORT_BY_QUALITY': False},
|
||||||
|
cutoff_at='2026-10-26T07:10:00+08:00', reason='晨版')
|
||||||
|
p = patch.object(plan, 'collect', side_effect=self.collect)
|
||||||
|
self.collect_mock = p.start()
|
||||||
|
self.addCleanup(p.stop)
|
||||||
|
p = patch.object(plan, 'write_published_md')
|
||||||
|
p.start()
|
||||||
|
self.addCleanup(p.stop)
|
||||||
|
|
||||||
|
def collect(self, day, **kw):
|
||||||
|
rows = copy.deepcopy(self.old['main'])
|
||||||
|
axis = plan.config.PLAN_RANK_AXIS
|
||||||
|
if axis == 'quality':
|
||||||
|
rows.sort(key=lambda r: -r['quality_band'])
|
||||||
|
for i, row in enumerate(rows, 1):
|
||||||
|
row.update(rank=i, rank_axis=axis)
|
||||||
|
return {'date': day, 'plan_version': 'test', 'rank_axis': axis, 'main': rows,
|
||||||
|
'observe': [], 'candidates': [], 'watch': [], '_full': {'main': rows, 'observe': []}}
|
||||||
|
|
||||||
|
def switch(self, **kw):
|
||||||
|
return rs.switch(now=NOW, **kw)
|
||||||
|
|
||||||
|
def apply(self, **kw):
|
||||||
|
with patch.object(config, 'PLAN_RANK_AXIS', 'quality'), patch.object(config, 'CARD_SORT_BY_QUALITY', True):
|
||||||
|
return self.switch(apply=True, expected_decision_id=pv.load(self.root)['decision']['id'], **kw)
|
||||||
|
|
||||||
|
def files(self):
|
||||||
|
return {str(p): p.read_bytes() for p in Path(self.root).rglob('*.json')}
|
||||||
|
|
||||||
|
def test_preview_does_not_change_published_bytes(self):
|
||||||
|
before = self.files()
|
||||||
|
result = self.switch()
|
||||||
|
self.assertEqual(result['status'], 'preview')
|
||||||
|
self.assertEqual(result['first20'][0]['code'], 'SH600002')
|
||||||
|
self.assertEqual(before, self.files())
|
||||||
|
|
||||||
|
def test_apply_preserves_history_and_inputs_and_is_idempotent(self):
|
||||||
|
original = self.files()
|
||||||
|
result = self.apply()
|
||||||
|
self.assertEqual(result['status'], 'published')
|
||||||
|
self.assertEqual(result['decision']['parent_id'], self.old['decision']['id'])
|
||||||
|
self.assertEqual(result['input_hash'], self.old['decision']['input_hash'])
|
||||||
|
self.assertEqual(pv.load(self.root, decision_id=self.old['decision']['id']), self.old)
|
||||||
|
self.assertEqual(pv.load(self.root, DAY, morning=True), self.old)
|
||||||
|
for path, value in original.items():
|
||||||
|
if Path(path).name.startswith(DAY + '_') or Path(path).name == 'morning.json':
|
||||||
|
self.assertEqual(Path(path).read_bytes(), value)
|
||||||
|
self.assertEqual(self.apply()['status'], 'unchanged')
|
||||||
|
|
||||||
|
def test_missing_or_changed_expected_version_refuses_write(self):
|
||||||
|
before = self.files()
|
||||||
|
for expected in (None, 'another'):
|
||||||
|
with self.assertRaisesRegex(ValueError, '版本已变化'):
|
||||||
|
self.switch(apply=True, expected_decision_id=expected)
|
||||||
|
self.assertEqual(before, self.files())
|
||||||
|
|
||||||
|
def test_wrong_runtime_configuration_refuses_write(self):
|
||||||
|
with patch.object(config, 'PLAN_RANK_AXIS', 'transmission'), self.assertRaisesRegex(ValueError, '运行配置'):
|
||||||
|
self.switch(apply=True, expected_decision_id=self.old['decision']['id'])
|
||||||
|
|
||||||
|
def test_previous_decision_day_refuses_rewrite(self):
|
||||||
|
with self.assertRaisesRegex(ValueError, '历史计划只读'):
|
||||||
|
rs.switch(now=NOW + dt.timedelta(days=1))
|
||||||
|
|
||||||
|
def test_pending_research_refuses_switch(self):
|
||||||
|
pv.health(self.root, DAY, pending_codes=['SH600001'], error=None)
|
||||||
|
with self.assertRaisesRegex(ValueError, '修订尚未完成'):
|
||||||
|
self.switch()
|
||||||
|
|
||||||
|
def test_qualification_drift_refuses_publication(self):
|
||||||
|
def changed(*a, **kw):
|
||||||
|
data = self.collect(*a, **kw)
|
||||||
|
data['_full']['main'][0]['verdict'] = '仅展示'
|
||||||
|
return data
|
||||||
|
self.collect_mock.side_effect = changed
|
||||||
|
with self.assertRaisesRegex(ValueError, '改变资格或研究'):
|
||||||
|
self.apply()
|
||||||
|
self.assertEqual(pv.load(self.root)['decision']['id'], self.old['decision']['id'])
|
||||||
|
|
||||||
|
def test_swallowed_missing_frozen_input_still_fails(self):
|
||||||
|
def missing(*a, **kw):
|
||||||
|
try:
|
||||||
|
pi.read('missing.source', lambda: self.fail('不得回源'))
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
return self.collect(*a, **kw)
|
||||||
|
self.collect_mock.side_effect = missing
|
||||||
|
with self.assertRaisesRegex(RuntimeError, '冻结输入缺失'):
|
||||||
|
self.apply()
|
||||||
|
|
||||||
|
def test_pool_reads_published_plan_without_live_assembly(self):
|
||||||
|
data = dict(self.old, main=[dict(self.old['main'][1], pointed=True)], refresh_status={})
|
||||||
|
with patch.object(plan, 'from_snapshot', return_value=data) as reader, \
|
||||||
|
patch.object(plan, 'collect', side_effect=AssertionError('不得现场重装配')), \
|
||||||
|
patch.object(pool, '_read_holdings', return_value=set()), \
|
||||||
|
patch.object(pool, '_read_bad_signals', return_value=(set(), None)), \
|
||||||
|
patch.object(pool, 'config_mongo_ready', return_value=False), \
|
||||||
|
patch.object(config, 'POOL_SOURCE', 'rank'), patch.object(config, 'POOL_WATCH_SLICE', 0):
|
||||||
|
result = pool.push(dry_run=True)
|
||||||
|
self.assertEqual(set(result['pool']), {'SH600002'})
|
||||||
|
reader.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Loading…
Reference in New Issue