Skip to content

Commit d115b1e

Browse files
committed
Update test_build_linkcheck.py
1 parent 1a0d9ed commit d115b1e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_builders/test_build_linkcheck.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,3 +1564,32 @@ def mock_request(self, method, url, **kwargs):
15641564
if lowercase_uri in rowsby:
15651565
# Should be working because case is ignored
15661566
assert rowsby[lowercase_uri]['status'] == 'working'
1567+
1568+
@pytest.mark.sphinx(
1569+
'linkcheck',
1570+
testroot='linkcheck-localserver-anchor',
1571+
freshenv=True,
1572+
confoverrides={'linkcheck_ignore_case': True},
1573+
)
1574+
1575+
def test_linkcheck_anchors_remain_case_sensitive(app: SphinxTestApp) -> None:
1576+
"""Test that anchors remain case-sensitive even with linkcheck_ignore_case=True."""
1577+
with serve_application(app, CaseSensitiveHandler) as address:
1578+
# Create a document with an anchor in lowercase that doesn't match HTML
1579+
index = app.srcdir / 'index.rst'
1580+
index.write_text(
1581+
f'* `Link with wrong case anchor <http://{address}/anchor.html#myanchor>`_\n',
1582+
encoding='utf-8',
1583+
)
1584+
app.build()
1585+
1586+
content = (app.outdir / 'output.json').read_text(encoding='utf8')
1587+
rows = [json.loads(x) for x in content.splitlines()]
1588+
1589+
# The HTML has "MyAnchor" but we request "myanchor"
1590+
# Even with linkcheck_ignore_case=True, anchors should be case-sensitive
1591+
# so this should be broken
1592+
assert len(rows) == 1
1593+
assert rows[0]['status'] == 'broken'
1594+
assert rows[0]['uri'] == f'http://{address}/anchor.html#myanchor'
1595+
assert "Anchor 'myanchor' not found" in rows[0]['info']

0 commit comments

Comments
 (0)