64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
"""技术暗标 HTML 格式检查:结构校验与极简用例(标准库 unittest)。"""
|
||
import json
|
||
import os
|
||
import sys
|
||
import unittest
|
||
|
||
# 保证可 `python tests/test_*.py` 从项目根导入 `modules`
|
||
_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
if _ROOT not in sys.path:
|
||
sys.path.insert(0, _ROOT)
|
||
|
||
from modules.dark_bid_format_check import check_technical_bid # noqa: E402
|
||
|
||
|
||
def _sample_schema_path():
|
||
return os.path.join(os.path.dirname(__file__), "fixtures", "dark_bid_report_sample.json")
|
||
|
||
|
||
class TestDarkBidFormatCheck(unittest.TestCase):
|
||
def test_sample_fixture_keys(self):
|
||
with open(_sample_schema_path(), encoding="utf-8") as f:
|
||
sample = json.load(f)
|
||
self.assertIn("overall", sample)
|
||
self.assertIn("details", sample)
|
||
self.assertIn("violations", sample)
|
||
for d in sample["details"]:
|
||
self.assertTrue({"rule", "passed", "message"}.issubset(d.keys()))
|
||
|
||
def test_check_returns_structure(self):
|
||
html = """<!DOCTYPE html><html><head><style>
|
||
@page { margin: 2.54cm 3.18cm 2.54cm 3.18cm; size: A4; }
|
||
</style></head><body style="margin:2.54cm 3.18cm">
|
||
<div class="toc">第一章 概述</div>
|
||
<h2 style="font-size:16pt;font-family:SimHei;font-weight:bold;color:#000">标题</h2>
|
||
<p style="font-size:14pt;font-family:SimSun;line-height:26pt;text-indent:2em;color:#000">
|
||
正文内容示例。</p>
|
||
</body></html>"""
|
||
r = check_technical_bid(html)
|
||
self.assertIsInstance(r["overall"], bool)
|
||
self.assertEqual(len(r["details"]), 7)
|
||
rules = [x["rule"] for x in r["details"]]
|
||
self.assertIn("身份信息隐藏", rules)
|
||
self.assertIn("标题格式", rules)
|
||
|
||
def test_empty_html(self):
|
||
r = check_technical_bid("")
|
||
self.assertFalse(r["overall"])
|
||
|
||
def test_identity_fail_on_company(self):
|
||
html = (
|
||
"<html><body><p style='font-size:14pt;font-family:SimSun;"
|
||
"line-height:26pt;text-indent:2em;color:#000'>我公司参与投标</p>"
|
||
"<div class='toc'>x</div>"
|
||
"<style>@page{margin:2.54cm 3.18cm 2.54cm 3.18cm}</style>"
|
||
"</body></html>"
|
||
)
|
||
r = check_technical_bid(html)
|
||
id_rule = next(x for x in r["details"] if x["rule"] == "身份信息隐藏")
|
||
self.assertFalse(id_rule["passed"])
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|