| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- """``scripts/acceptance_report.py`` 的结构测试。
- 只验证"报告把该说的都说清了":四段结构、配置审计能认出 v2 模板、
- 待现场项不会被漏掉。真正的耗时检查(全量单测/自检二进制)由命令行跑,
- 不在单测里重复执行。
- """
- from __future__ import annotations
- import importlib.util
- import os
- import unittest
- ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- SCRIPT = os.path.join(ROOT, "scripts", "acceptance_report.py")
- def _load():
- spec = importlib.util.spec_from_file_location("acceptance_report", SCRIPT)
- module = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(module)
- return module
- class AcceptanceReportTests(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- cls.mod = _load()
- def test_render_has_required_sections(self):
- text = self.mod.render(
- self.mod.audit_configs(), self.mod.audit_environment(),
- [("dummy check", "dummy", True, ["OK"])],
- )
- for section in ("## 1. 软件侧检查", "## 2. 配置审计",
- "## 3. 环境与证据盘点", "## 4. 待现场项"):
- self.assertIn(section, text)
- self.assertIn("| **PASS** |", text)
- def test_config_audit_covers_v2_templates(self):
- rows = {r["file"]: r for r in self.mod.audit_configs() if "error" not in r}
- self.assertIn("edge-v2-front.json", rows)
- self.assertTrue(rows["edge-v2-front.json"]["ev2"])
- self.assertTrue(rows["edge-v2-front.json"]["commit"])
- self.assertTrue(rows["edge-v2-front.json"]["allow2"])
- self.assertIn("edge-v2-rtsp.json", rows)
- self.assertEqual(rows["edge-v2-rtsp.json"]["source"], "rtsp")
- def test_v1_template_reports_state2_disabled(self):
- # v1(edge-cpp.json)必须显示 "不允许平车 2",否则报告会误导验收。
- rows = {r["file"]: r for r in self.mod.audit_configs() if "error" not in r}
- self.assertIn("edge-cpp.json", rows)
- self.assertFalse(rows["edge-cpp.json"]["allow2"])
- def test_field_items_documented(self):
- names = [name for name, _need in self.mod.FIELD_ITEMS]
- self.assertGreaterEqual(len(names), 5)
- self.assertTrue(any("PLC" in n for n in names))
- self.assertTrue(any("RTSP" in n for n in names))
- if __name__ == "__main__":
- unittest.main()
|