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