summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2022-05-20 17:26:12 -0400
committerNed Batchelder <ned@nedbatchelder.com>2022-05-20 17:43:24 -0400
commit907d646952297e8116d247b94868fe173e76043b (patch)
tree76fbce57c65277a2229d07c6a1c27dbe60529110
parent1f658e99a5ec4ce9fe7a70392fd88b3462ae2554 (diff)
downloadpython-coveragepy-git-907d646952297e8116d247b94868fe173e76043b.tar.gz
test: tests of HTML's helper assert_valid_hrefs
-rw-r--r--tests/test_html.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/test_html.py b/tests/test_html.py
index cd2b0aa7..d649c67f 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -109,7 +109,9 @@ class HtmlTestHelpers(CoverageTest):
html = fhtml.read()
for href in re.findall(r""" href=['"]([^'"]*)['"]""", html):
if href.startswith("#"):
- assert re.search(rf""" id=['"]{href[1:]}['"]""", html)
+ assert re.search(rf""" id=['"]{href[1:]}['"]""", html), (
+ f"Fragment {href!r} in {fname} has no anchor"
+ )
continue
if "://" in href:
continue
@@ -1188,3 +1190,21 @@ class HtmlWithContextsTest(HtmlTestHelpers, CoverageTest):
if label == ld.contexts_label or label in (ld.contexts or ())
]
assert sorted(expected) == sorted(actual)
+
+
+class HtmlHelpersTest(HtmlTestHelpers, CoverageTest):
+ """Tests of the helpers in HtmlTestHelpers."""
+
+ def test_bad_link(self):
+ # Does assert_valid_hrefs detect links to non-existent files?
+ self.make_file("htmlcov/index.html", "<a href='nothing.html'>Nothing</a>")
+ msg = "These files link to 'nothing.html', which doesn't exist: htmlcov.index.html"
+ with pytest.raises(AssertionError, match=msg):
+ self.assert_valid_hrefs()
+
+ def test_bad_anchor(self):
+ # Does assert_valid_hrefs detect fragments that go nowhere?
+ self.make_file("htmlcov/index.html", "<a href='#nothing'>Nothing</a>")
+ msg = "Fragment '#nothing' in htmlcov.index.html has no anchor"
+ with pytest.raises(AssertionError, match=msg):
+ self.assert_valid_hrefs()