Pair black and bright defect evidence for priority products
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "scripts"))
|
||||
sys.path.insert(0, str(ROOT / "verification"))
|
||||
|
||||
from nao_product_defect_pairing import plan_missing_product_defect_stages
|
||||
from nao_quality_tools import QualityTools
|
||||
from analysis_visual_evidence import load_visual_evidence
|
||||
from test_nao_quality_tools import FakeApi
|
||||
|
||||
|
||||
def evidence(product: str, stage: str, *, month: int = 9):
|
||||
return {"result": {"kind": "quality_fine_defects", "releaseId": "release-a",
|
||||
"dimension": "defect", "stage": stage, "period": {"year": 2026, "month": month},
|
||||
"comparisonPeriod": {"year": 2026, "month": 8},
|
||||
"filters": {"product": product, "includeUnassigned": False},
|
||||
"category": None, "defect": None, "sort": "scrap_delta"}}
|
||||
|
||||
|
||||
class ProductDefectPairingTests(unittest.TestCase):
|
||||
def test_fills_only_missing_stage_for_same_product_and_period(self):
|
||||
docs = [evidence("16.33", "black"), evidence("16.33", "bright"),
|
||||
evidence("R127", "black"), evidence("R127", "black")]
|
||||
planned = plan_missing_product_defect_stages(docs, "分析近期重点产品")
|
||||
self.assertEqual(len(planned), 1)
|
||||
self.assertEqual(planned[0]["stage"], "bright")
|
||||
self.assertEqual(planned[0]["filters"]["product"], "R127")
|
||||
self.assertEqual(planned[0]["comparisonPeriod"], {"year": 2026, "month": 8})
|
||||
|
||||
def test_does_not_join_different_period_or_release(self):
|
||||
docs = [evidence("R127", "black"), evidence("R127", "bright", month=10)]
|
||||
planned = plan_missing_product_defect_stages(docs, "重点规格")
|
||||
self.assertEqual({p["stage"] for p in planned}, {"black", "bright"})
|
||||
|
||||
def test_explicit_single_stage_scope_stays_single(self):
|
||||
docs = [evidence("R127", "black")]
|
||||
self.assertEqual(plan_missing_product_defect_stages(docs, "只看黑片来源缺陷"), [])
|
||||
self.assertEqual(plan_missing_product_defect_stages(docs, "重点规格", {"stage": "black"}), [])
|
||||
|
||||
def test_unscoped_or_category_specific_defects_do_not_trigger_product_pair(self):
|
||||
doc = evidence("R127", "black")
|
||||
doc["result"]["filters"].pop("product")
|
||||
self.assertEqual(plan_missing_product_defect_stages([doc], "重点规格"), [])
|
||||
doc["result"]["filters"]["product"] = "R127"
|
||||
doc["result"]["category"] = "责废"
|
||||
self.assertEqual(plan_missing_product_defect_stages([doc], "重点规格"), [])
|
||||
|
||||
def test_counterpart_query_creates_separate_traceable_evidence(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
api = FakeApi()
|
||||
tools = QualityTools(api_factory=lambda: api, evidence_dir=folder)
|
||||
tools.quality_data({"mode": "defects", "releaseId": "release-a",
|
||||
"period": {"year": 2026, "month": 3},
|
||||
"comparisonPeriod": {"year": 2026, "month": 1},
|
||||
"filters": {"product": "规格 A"}, "stage": "black",
|
||||
"dimension": "defect", "limit": 10})
|
||||
docs = load_visual_evidence(Path(folder), "release-a")
|
||||
planned = plan_missing_product_defect_stages(docs, "分析重点规格的具体缺陷")
|
||||
self.assertEqual(len(planned), 1)
|
||||
tools.quality_data(planned[0])
|
||||
paired_docs = load_visual_evidence(Path(folder), "release-a")
|
||||
self.assertEqual({d["result"]["stage"] for d in paired_docs}, {"black", "bright"})
|
||||
self.assertEqual(len({d["evidenceRef"] for d in paired_docs}), 2)
|
||||
self.assertEqual(plan_missing_product_defect_stages(paired_docs, "分析重点规格的具体缺陷"), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user