Skip to content

Commit

Permalink
Add test coverage for anchor-in-document linkchecking
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Apr 11, 2023
1 parent 5d67627 commit 3115b20
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tests/roots/test-linkcheck/anchor.html
@@ -0,0 +1,5 @@
<html>
<body>
<a id="found"></a>
</body>
</html>
1 change: 1 addition & 0 deletions tests/roots/test-linkcheck/links.rst
Expand Up @@ -11,3 +11,4 @@ Some additional anchors to exercise ignore code
.. image:: http://localhost:7777/image.png
.. figure:: http://localhost:7777/image2.png

* `Valid anchored url <http://localhost:7777/anchor.html#found>`_
19 changes: 17 additions & 2 deletions tests/test_build_linkcheck.py
Expand Up @@ -31,6 +31,9 @@ def do_HEAD(self):
if self.path[1:].rstrip() == "":
self.send_response(200, "OK")
self.end_headers()
elif self.path[1:].rstrip() == "anchor.html":
self.send_response(200, "OK")
self.end_headers()
else:
self.send_response(404, "Not Found")
self.end_headers()
Expand All @@ -39,6 +42,9 @@ def do_GET(self):
self.do_HEAD()
if self.path[1:].rstrip() == "":
self.wfile.write(b"ok\n\n")
elif self.path[1:].rstrip() == "anchor.html":
doc = '<!DOCTYPE html>><html><body><a id="found"></a></body></html>'
self.wfile.write(doc.encode('utf-8'))


@pytest.mark.sphinx('linkcheck', testroot='linkcheck', freshenv=True)
Expand Down Expand Up @@ -69,8 +75,8 @@ def test_defaults(app):
for attr in ("filename", "lineno", "status", "code", "uri", "info"):
assert attr in row

assert len(content.splitlines()) == 9
assert len(rows) == 9
assert len(content.splitlines()) == 10
assert len(rows) == 10
# the output order of the rows is not stable
# due to possible variance in network latency
rowsby = {row["uri"]: row for row in rows}
Expand All @@ -95,6 +101,15 @@ def test_defaults(app):
assert rowsby["http://localhost:7777#does-not-exist"]["info"] == "Anchor 'does-not-exist' not found"
# images should fail
assert "Not Found for url: http://localhost:7777/image.png" in rowsby["http://localhost:7777/image.png"]["info"]
# anchor should be found
assert rowsby['http://localhost:7777/anchor.html#found'] == {
'filename': 'links.rst',
'lineno': 14,
'status': 'working',
'code': 0,
'uri': 'http://localhost:7777/anchor.html#found',
'info': '',
}


@pytest.mark.sphinx('linkcheck', testroot='linkcheck-too-many-retries', freshenv=True)
Expand Down

0 comments on commit 3115b20

Please sign in to comment.