sphinx/tests/test_extensions/test_ext_autosectionlabel.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
3.2 KiB
Python
Raw Normal View History

"""Test sphinx.ext.autosectionlabel extension."""
from __future__ import annotations
import re
import pytest
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel')
2025-01-17 18:35:09 -06:00
def test_autosectionlabel_html(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
content = (app.outdir / 'index.html').read_text(encoding='utf8')
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" href="#introduce-of-sphinx">'
'<span class=".*?">Introduce of Sphinx</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" href="#installation">'
'<span class="std std-ref">Installation</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" href="#for-windows-users">'
'<span class="std std-ref">For Windows users</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" href="#for-unix-users">'
'<span class="std std-ref">For UNIX users</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" href="#linux">'
'<span class="std std-ref">Linux</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" href="#freebsd">'
'<span class="std std-ref">FreeBSD</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2018-02-10 22:54:47 -06:00
# for smart_quotes (refs: #4027)
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" '
'href="#this-one-s-got-an-apostrophe">'
'<span class="std std-ref">This ones got an apostrophe'
'</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2024-01-03 20:37:44 -06:00
# Reuse test definition from above, just change the test root directory
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel-prefix-document')
def test_autosectionlabel_prefix_document_html(app):
test_autosectionlabel_html(app)
2024-08-11 08:58:56 -05:00
@pytest.mark.sphinx(
'html',
testroot='ext-autosectionlabel',
confoverrides={'autosectionlabel_maxdepth': 3},
)
def test_autosectionlabel_maxdepth(app):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
2019-02-11 03:34:04 -06:00
content = (app.outdir / 'index.html').read_text(encoding='utf8')
2019-02-11 03:34:04 -06:00
# depth: 1
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" href="#test-ext-autosectionlabel">'
'<span class=".*?">test-ext-autosectionlabel</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2019-02-11 03:34:04 -06:00
# depth: 2
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" href="#installation">'
'<span class="std std-ref">Installation</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2019-02-11 03:34:04 -06:00
# depth: 3
2024-08-11 08:58:56 -05:00
html = (
'<li><p><a class="reference internal" href="#for-windows-users">'
'<span class="std std-ref">For Windows users</span></a></p></li>'
)
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2019-02-11 03:34:04 -06:00
# depth: 4
html = '<li><p><span class="xref std std-ref">Linux</span></p></li>'
2024-01-18 20:16:48 -06:00
assert re.search(html, content, re.DOTALL)
2019-02-11 03:34:04 -06:00
assert "WARNING: undefined label: 'linux'" in app.warning.getvalue()