diff --git a/tests/roots/test-linkcheck/anchor.html b/tests/roots/test-linkcheck/anchor.html new file mode 100644 index 00000000000..ad7ef5ac1ee --- /dev/null +++ b/tests/roots/test-linkcheck/anchor.html @@ -0,0 +1,5 @@ + + + + + diff --git a/tests/roots/test-linkcheck/links.rst b/tests/roots/test-linkcheck/links.rst index 49afba2b39a..88c757e03d9 100644 --- a/tests/roots/test-linkcheck/links.rst +++ b/tests/roots/test-linkcheck/links.rst @@ -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 `_ diff --git a/tests/test_build_linkcheck.py b/tests/test_build_linkcheck.py index acfebd64999..718a2796464 100644 --- a/tests/test_build_linkcheck.py +++ b/tests/test_build_linkcheck.py @@ -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() @@ -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 = '>' + self.wfile.write(doc.encode('utf-8')) @pytest.mark.sphinx('linkcheck', testroot='linkcheck', freshenv=True) @@ -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} @@ -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)