"""
test_ext_autosectionlabel
~~~~~~~~~~~~~~~~~~~~~~~~~
Test sphinx.ext.autosectionlabel extension.
:copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
import pytest
from sphinx.util import docutils
@pytest.mark.skipif(docutils.__version_info__ < (0, 13),
reason='docutils-0.13 or above is required')
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel')
def test_autosectionlabel_html(app, status, warning, skipped_labels=False):
app.builder.build_all()
content = (app.outdir / 'index.html').read_text()
html = ('
'
'Introduce of Sphinx
')
assert re.search(html, content, re.S)
html = (''
'Installation
')
assert re.search(html, content, re.S)
html = (''
'For Windows users
')
assert re.search(html, content, re.S)
html = (''
'For UNIX users
')
assert re.search(html, content, re.S)
html = (''
'Linux
')
assert re.search(html, content, re.S)
html = (''
'FreeBSD
')
assert re.search(html, content, re.S)
# for smart_quotes (refs: #4027)
html = (''
'This one’s got an apostrophe'
'
')
assert re.search(html, content, re.S)
# Re-use test definition from above, just change the test root directory
@pytest.mark.skipif(docutils.__version_info__ < (0, 13),
reason='docutils-0.13 or above is required')
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel-prefix-document')
def test_autosectionlabel_prefix_document_html(app, status, warning):
test_autosectionlabel_html(app, status, warning)
@pytest.mark.skipif(docutils.__version_info__ < (0, 13),
reason='docutils-0.13 or above is required')
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel',
confoverrides={'autosectionlabel_maxdepth': 3})
def test_autosectionlabel_maxdepth(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'index.html').read_text()
# depth: 1
html = (''
'test-ext-autosectionlabel
')
assert re.search(html, content, re.S)
# depth: 2
html = (''
'Installation
')
assert re.search(html, content, re.S)
# depth: 3
html = (''
'For Windows users
')
assert re.search(html, content, re.S)
# depth: 4
html = 'Linux
'
assert re.search(html, content, re.S)
assert 'WARNING: undefined label: linux' in warning.getvalue()