Skip to content

Commit f16360e

Browse files
committed
updated
1 parent c907bd9 commit f16360e

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

tests/test_optional_audits.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
from __future__ import annotations
33

44
import json
5+
import sys
6+
from unittest.mock import patch
57

68
import pandas as pd
79

810
from website_profiling.reporting.optional_audits import (
911
amp_audit_issues,
1012
apply_optional_audits,
13+
html_validation_issues,
1114
pagination_issues,
15+
spell_check_issues,
1216
)
1317

1418

@@ -38,12 +42,37 @@ def test_amp_audit_missing_canonical():
3842
assert len(issues) == 1
3943

4044

41-
def test_apply_optional_audits_spell_skipped_without_package():
45+
def test_spell_check_issues_missing_pyspellchecker():
46+
df = pd.DataFrame([
47+
{
48+
"url": "https://example.com/typo",
49+
"status": "200",
50+
"content_excerpt": "This sentense has many misspelled wrds that should trigger heuristics.",
51+
},
52+
])
53+
with patch.dict(sys.modules, {"spellchecker": None}):
54+
issues, skip = spell_check_issues(df)
55+
assert issues == []
56+
assert skip and "pyspellchecker" in skip
57+
58+
59+
def test_html_validation_issues_missing_html5lib():
60+
html = "<html><head><title>A</title></head><body>" + ("x" * 120) + "</body></html>"
61+
df = pd.DataFrame([{"url": "https://example.com", "html": html}])
62+
with patch.dict(sys.modules, {"html5lib": None}):
63+
issues, use_parser = html_validation_issues(df)
64+
assert use_parser is False
65+
assert isinstance(issues, list)
66+
67+
68+
def test_apply_optional_audits_spell_skipped_without_package(capsys):
4269
categories = [
4370
{"id": "technical_seo", "name": "Technical", "issues": [], "recommendations": []},
4471
{"id": "intelligence", "name": "Content", "issues": [], "recommendations": []},
4572
{"id": "html_accessibility", "name": "A11y", "issues": [], "recommendations": []},
4673
]
4774
df = pd.DataFrame([{"url": "https://example.com", "status": "200", "page_analysis": "{}"}])
48-
meta = apply_optional_audits(categories, df, {"enable_spell_check": "true"})
49-
assert isinstance(meta, dict)
75+
with patch.dict(sys.modules, {"spellchecker": None}):
76+
meta = apply_optional_audits(categories, df, {"enable_spell_check": "true"})
77+
assert meta["spell_check_skipped"] == "pyspellchecker not installed (pip install -r requirements.txt)"
78+
assert "pyspellchecker" in capsys.readouterr().err

0 commit comments

Comments
 (0)