verify_optimized_plan.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. from docx import Document
  3. from docx.oxml.ns import qn
  4. from zipfile import ZipFile
  5. from pathlib import Path
  6. p = Path("在线考试系统实现方案(优化定稿版).docx")
  7. doc = Document(p)
  8. parts = [x.text for x in doc.paragraphs]
  9. for table in doc.tables:
  10. for row in table.rows:
  11. for cell in row.cells:
  12. parts.append(cell.text)
  13. text = chr(10).join(parts)
  14. headings = [(x.style.name, x.text) for x in doc.paragraphs if x.style.name.startswith("Heading")]
  15. required = [
  16. "方案 B + 评审整改 + 协议补强", "P0", "P1", "P2", "R1", "R10",
  17. "answer_item(session_id, question_id)", "answer_operation", "opId", "payloadHash",
  18. "base_version", "server_seq", "STALE_VERSION", "SUBMIT_UNKNOWN",
  19. "UNIQUE submission(session_id)", "requestHash", "C10", "13 周",
  20. "2026-11-10", "不能直接复用", "不能证明其已经实现", "R8 未关闭",
  21. "先证明“不会错”,再测量“跑多快”"
  22. ]
  23. for s in required:
  24. assert s in text, s
  25. for bad in ["TODO", "待补充", "待填写"]:
  26. assert bad not in text, bad
  27. assert len(doc.tables) == 21, len(doc.tables)
  28. assert "DUPLICATE_CONTENT" not in text
  29. assert "CONTENT_ALREADY_EQUAL" in text
  30. assert "会话语义正确率 = 故障结束后" in text
  31. assert "status、next_seq、version" not in text
  32. assert "状态迁移用会话行锁,不另设version" in text
  33. for status in ["APPLIED", "DUPLICATE", "STALE_VERSION", "SESSION_CLOSED", "REJECTED"]:
  34. assert status in text
  35. from optimized_plan_content import EXAM_ANSWER, PROCTOR_EVENT, PROCTOR_SESSION
  36. for link in [EXAM_ANSWER, PROCTOR_EVENT, PROCTOR_SESSION]:
  37. assert "/blob/master/" in link and "/domain/entity/" not in link and "/blob/main/" not in link
  38. with ZipFile(p) as z:
  39. xml = z.read("word/document.xml").decode("utf-8")
  40. assert "TOC " in xml and "1-2" in xml
  41. assert xml.count("<w:hyperlink") >= 9
  42. settings = z.read("word/settings.xml").decode("utf-8")
  43. assert "updateFields" in settings
  44. print("path:", p.resolve())
  45. print("bytes:", p.stat().st_size, "paragraphs:", len(doc.paragraphs), "tables:", len(doc.tables), "headings:", len(headings))
  46. print("hyperlinks:", xml.count("<w:hyperlink"))
  47. print("top-level headings:")
  48. for style, value in headings:
  49. if style == "Heading 1": print(" -", value)
  50. print("All structural and content checks passed.")