"""Test sphinx.ext.autosectionlabel extension."""
from __future__ import annotations
import re
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel')
def test_autosectionlabel_html(app: SphinxTestApp) -> None:
app.build(force_all=True)
content = (app.outdir / 'index.html').read_text(encoding='utf8')
html = (
'
'
'Introduce of Sphinx
'
)
assert re.search(html, content, re.DOTALL)
html = (
''
'Installation
'
)
assert re.search(html, content, re.DOTALL)
html = (
''
'For Windows users
'
)
assert re.search(html, content, re.DOTALL)
html = (
''
'For UNIX users
'
)
assert re.search(html, content, re.DOTALL)
html = (
''
'Linux
'
)
assert re.search(html, content, re.DOTALL)
html = (
''
'FreeBSD
'
)
assert re.search(html, content, re.DOTALL)
# for smart_quotes
# See: https://github.com/sphinx-doc/sphinx/issues/4027
html = (
''
'This one’s got an apostrophe'
'
'
)
assert re.search(html, content, re.DOTALL)
# 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: SphinxTestApp) -> None:
test_autosectionlabel_html(app)
@pytest.mark.sphinx(
'html',
testroot='ext-autosectionlabel',
confoverrides={'autosectionlabel_maxdepth': 3},
)
def test_autosectionlabel_maxdepth(app: SphinxTestApp) -> None:
app.build(force_all=True)
content = (app.outdir / 'index.html').read_text(encoding='utf8')
# depth: 1
html = (
''
'test-ext-autosectionlabel
'
)
assert re.search(html, content, re.DOTALL)
# depth: 2
html = (
''
'Installation
'
)
assert re.search(html, content, re.DOTALL)
# depth: 3
html = (
''
'For Windows users
'
)
assert re.search(html, content, re.DOTALL)
# depth: 4
html = 'Linux
'
assert re.search(html, content, re.DOTALL)
assert "WARNING: undefined label: 'linux'" in app.warning.getvalue()