mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-07-31 16:47:59 -05:00
Ensure that `linkcheck_anchors` is properly respected (#11544)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
co-authored by
Adam Turner
parent
89808c6f49
commit
06c1339bb3
@@ -16,6 +16,10 @@ Features added
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
* #11542: linkcheck: Properly respect :confval:`linkcheck_anchors`
|
||||
and do not spuriously report failures to validate anchors.
|
||||
Patch by James Addison.
|
||||
|
||||
Testing
|
||||
-------
|
||||
|
||||
|
||||
@@ -406,7 +406,8 @@ class HyperlinkAvailabilityCheckWorker(Thread):
|
||||
_user_agent=self.user_agent,
|
||||
_tls_info=(self.tls_verify, self.tls_cacerts),
|
||||
) as response:
|
||||
if response.ok and anchor and not contains_anchor(response, anchor):
|
||||
if (self.check_anchors and response.ok and anchor
|
||||
and not contains_anchor(response, anchor)):
|
||||
raise Exception(__(f'Anchor {anchor!r} not found'))
|
||||
|
||||
# Copy data we need from the (closed) response
|
||||
|
||||
@@ -152,6 +152,7 @@ def test_defaults(app):
|
||||
}
|
||||
# looking for '#top' and '#does-not-exist' not found should fail
|
||||
assert rowsby["http://localhost:7777/#top"]["info"] == "Anchor 'top' not found"
|
||||
assert rowsby["http://localhost:7777/#top"]["status"] == "broken"
|
||||
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"]
|
||||
@@ -166,6 +167,22 @@ def test_defaults(app):
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.sphinx(
|
||||
'linkcheck', testroot='linkcheck', freshenv=True,
|
||||
confoverrides={'linkcheck_anchors': False})
|
||||
def test_check_link_response_only(app):
|
||||
with http_server(DefaultsHandler):
|
||||
app.build()
|
||||
|
||||
# JSON output
|
||||
assert (app.outdir / 'output.json').exists()
|
||||
content = (app.outdir / 'output.json').read_text(encoding='utf8')
|
||||
|
||||
rows = [json.loads(x) for x in content.splitlines()]
|
||||
rowsby = {row["uri"]: row for row in rows}
|
||||
assert rowsby["http://localhost:7777/#top"]["status"] == "working"
|
||||
|
||||
|
||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-too-many-retries', freshenv=True)
|
||||
def test_too_many_retries(app):
|
||||
with http_server(DefaultsHandler):
|
||||
|
||||
Reference in New Issue
Block a user