"""规则候选四类例证与完整只读诊断;不把预览当作规则启用或文学认证。""" from copy import deepcopy import pytest from muse.审校修订.接口 import ( 审校错误, 核对规则, 核对规则启用, 核对规则库, 诊断文本, 读取内置规则, ) @pytest.mark.case_id( "NC-w22-228001", environment="默认离线", given="规则种子候选与四类例证双向对应", when="经B06公共用例及真实声明环境执行", then=["规则种子候选与四类例证双向对应"], contract="docs/系统架构/新版设计/模块设计/B06-审校修订.md", ) def test_规则种子候选与四类例证双向对应__228001(): 库 = 读取内置规则() assert len(库["rules"]) == 26 and len(库["samples"]) == 107 for r in 库["rules"].values(): assert r["status"] == "candidate" for kind in ("sf", "snf", "boundary", "regression"): assert r["samples"][kind] for id_ in r["samples"][kind]: assert 库["samples"][id_]["type"] == kind assert r["id"] in 库["samples"][id_]["rules"] with pytest.raises(审校错误, match="B10"): 核对规则启用(r, 库["samples"], {"self_reported": True}) @pytest.mark.case_id( "NC-w22-228002", environment="默认离线", given="坏规则或例证缺口不能装载", when="经B06公共用例及真实声明环境执行", then=["坏规则或例证缺口不能装载"], contract="docs/系统架构/新版设计/模块设计/B06-审校修订.md", ) @pytest.mark.parametrize( "坏处", ["缺类", "缺样例", "错类", "反向引用", "重复规则", "重复例证", "未知触发器"] ) def test_坏规则或例证缺口不能装载__228002(坏处): 库 = deepcopy(读取内置规则()) r = 库["rules"]["l002"] s = 库["samples"] if 坏处 == "缺类": r["samples"]["regression"] = [] elif 坏处 == "缺样例": r["samples"]["sf"] = ["不存在"] elif 坏处 == "错类": s[r["samples"]["sf"][0]]["type"] = "snf" elif 坏处 == "反向引用": s[r["samples"]["sf"][0]]["rules"] = [] elif 坏处 == "未知触发器": r["trigger"]["type"] = "script" with pytest.raises(审校错误): if 坏处 == "重复规则": 核对规则库([r, r], list(s.values())) elif 坏处 == "重复例证": 核对规则库([r], list(s.values()) + [next(iter(s.values()))]) else: 核对规则(r, s) @pytest.mark.case_id( "NC-w22-228003", environment="默认离线", given="候选预览全文对白与有意表达不误判", when="经B06公共用例及真实声明环境执行", then=["候选预览全文对白与有意表达不误判"], contract="docs/系统架构/新版设计/模块设计/B06-审校修订.md", ) def test_候选预览全文对白与有意表达不误判__228003(): 库 = 读取内置规则() 文本 = "「值得注意的是,这是对白。」" + "雨落下来。" * 9000 + "值得注意的是,这是叙述。" assert 诊断文本(文本, work_id="w", 规则库=库)["findings"] == [] 报告 = 诊断文本(文本, work_id="w", 规则库=库, 预览候选=True) 发现 = [r for r in 报告["findings"] if r["rule_id"] == "l002"] assert len(发现) == 1 and 发现[0]["start"] > 40000 assert 发现[0]["quote"] == 文本[发现[0]["start"] : 发现[0]["end"]] assert 发现[0]["carrier"] == "narration" and 发现[0]["decision_proposal"] == "ask" assert 报告["coverage"]["deterministic"] == [[0, len(文本)]] assert 报告["unreviewed_rules"] and 报告["calibration"] == "uncalibrated" 保护 = 诊断文本(文本, work_id="w", 规则库=库, 预览候选=True, 保护表达=("值得注意的是",)) assert ( next(r for r in 保护["findings"] if r["rule_id"] == "l002")["decision_proposal"] == "retain" ) @pytest.mark.case_id( "NC-w22-228004", environment="默认离线", given="空正文或无作品拒绝诊断", when="经B06公共用例及真实声明环境执行", then=["空正文或无作品拒绝诊断"], contract="docs/系统架构/新版设计/模块设计/B06-审校修订.md", ) @pytest.mark.parametrize("文本,作品", [("", "w"), (" ", "w"), ("正常文字。", "")]) def test_空正文或无作品拒绝诊断__228004(文本, 作品): with pytest.raises(审校错误): 诊断文本(文本, work_id=作品, 规则库=读取内置规则()) @pytest.mark.case_id( "NC-w22-228005", environment="默认离线", given="指纹覆盖所有内容而非只看版本号", when="经B06公共用例及真实声明环境执行", then=["指纹覆盖所有内容而非只看版本号"], contract="docs/系统架构/新版设计/模块设计/B06-审校修订.md", ) def test_指纹覆盖所有内容而非只看版本号__228005(): 库 = 读取内置规则() r = deepcopy(库) r["rules"]["l001"]["fix_hint"] = "新的处置意见" with pytest.raises(审校错误, match="指纹"): 诊断文本("正常文字。", work_id="w", 规则库=r) 新 = 核对规则库(list(r["rules"].values()), list(r["samples"].values())) assert 新["fingerprint"] != 库["fingerprint"] 报告 = 诊断文本("春天到了。", work_id="w", 规则库=库, 预览候选=True) assert 报告["findings"] == [] and 报告["executed_rules"] and not 报告["persisted"]