iftypeset/tests/test_qa.py
2026-01-03 20:29:35 +00:00

38 lines
1.4 KiB
Python

import sys
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "src"
sys.path.insert(0, str(SRC))
from iftypeset.qa import analyze_html, evaluate_gates # noqa: E402
from iftypeset.spec_loader import load_spec # noqa: E402
class QATests(unittest.TestCase):
def test_analyze_html_metrics(self) -> None:
spec = load_spec(ROOT / "spec")
profile = spec.profiles["web_pdf"]
html_text = """
<!doctype html>
<html><body>
<h1>1 Intro</h1>
<h2>1.2 Skip</h2>
<p>Paragraph with a very long URL <a href="https://example.com/this/is/a/very/long/url/that/should/trigger/and/keep/going/without/breaks">https://example.com/this/is/a/very/long/url/that/should/trigger/and/keep/going/without/breaks</a></p>
<pre><code>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</code></pre>
</body></html>
"""
report = analyze_html(html_text, profile)
self.assertIn("max_link_wrap_incidents", report.metrics)
self.assertGreaterEqual(report.metrics["max_link_wrap_incidents"], 1)
def test_gate_evaluation(self) -> None:
metrics = {"max_link_wrap_incidents": 3}
gates = {"max_link_wrap_incidents": 1}
result = evaluate_gates(metrics, gates, profile_id="web_pdf", strict=False)
self.assertFalse(result["ok"])
if __name__ == "__main__":
unittest.main()