sphinx/tests/test_ext_autosectionlabel.py

92 lines
3.4 KiB
Python
Raw Normal View History

"""
test_ext_autosectionlabel
~~~~~~~~~~~~~~~~~~~~~~~~~
Test sphinx.ext.autosectionlabel extension.
2019-01-02 01:00:30 -06:00
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
import pytest
2019-01-02 10:05:16 -06:00
from sphinx.util import docutils
2019-01-02 10:05:16 -06:00
@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').text()
2019-01-02 10:05:16 -06:00
html = ('<li><p><a class="reference internal" href="#introduce-of-sphinx">'
'<span class=".*?">Introduce of Sphinx</span></a></p></li>')
assert re.search(html, content, re.S)
2019-01-02 10:05:16 -06:00
html = ('<li><p><a class="reference internal" href="#installation">'
'<span class="std std-ref">Installation</span></a></p></li>')
assert re.search(html, content, re.S)
2019-01-02 10:05:16 -06:00
html = ('<li><p><a class="reference internal" href="#for-windows-users">'
'<span class="std std-ref">For Windows users</span></a></p></li>')
assert re.search(html, content, re.S)
2019-01-02 10:05:16 -06:00
html = ('<li><p><a class="reference internal" href="#for-unix-users">'
'<span class="std std-ref">For UNIX users</span></a></p></li>')
assert re.search(html, content, re.S)
2019-02-11 03:34:04 -06:00
html = ('<li><a class="reference internal" href="#linux">'
'<span class="std std-ref">Linux</span></a></li>')
assert re.search(html, content, re.S)
2019-02-11 03:34:04 -06:00
html = ('<li><a class="reference internal" href="#freebsd">'
'<span class="std std-ref">FreeBSD</span></a></li>')
assert re.search(html, content, re.S)
2018-02-10 22:54:47 -06:00
# for smart_quotes (refs: #4027)
2019-01-02 10:05:16 -06:00
html = ('<li><p><a class="reference internal" '
2018-12-15 08:02:28 -06:00
'href="#this-one-s-got-an-apostrophe">'
'<span class="std std-ref">This ones got an apostrophe'
2019-01-02 10:05:16 -06:00
'</span></a></p></li>')
assert re.search(html, content, re.S)
# Re-use test definition from above, just change the test root directory
2019-01-02 10:05:16 -06:00
@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):
2019-02-11 03:34:04 -06:00
test_autosectionlabel_html(app, status, warning)
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel',
confoverrides={'autosectionlabel_maxdepth': 3})
def test_autosectionlabel_maxdepth(app, status, warning):
2019-02-11 03:34:04 -06:00
app.builder.build_all()
content = (app.outdir / 'index.html').text()
# depth: 1
html = ('<li><a class="reference internal" href="#test-ext-autosectionlabel">'
'<span class=".*?">test-ext-autosectionlabel</span></a></li>')
assert re.search(html, content, re.S)
# depth: 2
html = ('<li><a class="reference internal" href="#installation">'
'<span class="std std-ref">Installation</span></a></li>')
assert re.search(html, content, re.S)
# depth: 3
html = ('<li><a class="reference internal" href="#for-windows-users">'
'<span class="std std-ref">For Windows users</span></a></li>')
assert re.search(html, content, re.S)
# depth: 4
html = '<li><span class="xref std std-ref">Linux</span></li>'
assert re.search(html, content, re.S)
assert 'WARNING: undefined label: linux' in warning.getvalue()