2016-02-14 01:07:32 -06:00
|
|
|
|
"""
|
|
|
|
|
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.
|
2016-02-14 01:07:32 -06:00
|
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
|
import pytest
|
2016-02-14 01:07:32 -06:00
|
|
|
|
|
2019-01-02 10:05:16 -06:00
|
|
|
|
from sphinx.util import docutils
|
2016-02-14 01:07:32 -06:00
|
|
|
|
|
2019-01-02 10:05:16 -06:00
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(docutils.__version_info__ < (0, 13),
|
|
|
|
|
reason='docutils-0.13 or above is required')
|
2017-01-05 10:14:47 -06:00
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel')
|
2017-11-26 08:02:36 -06:00
|
|
|
|
def test_autosectionlabel_html(app, status, warning, skipped_labels=False):
|
2016-02-14 01:07:32 -06:00
|
|
|
|
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>')
|
2016-02-14 01:07:32 -06:00
|
|
|
|
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>')
|
2016-02-14 01:07:32 -06:00
|
|
|
|
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>')
|
2016-02-14 01:07:32 -06:00
|
|
|
|
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>')
|
2016-02-14 01:07:32 -06:00
|
|
|
|
assert re.search(html, content, re.S)
|
2017-02-03 18:23:16 -06:00
|
|
|
|
|
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)
|
2017-11-26 08:02:36 -06:00
|
|
|
|
|
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)
|
2017-11-26 08:02:36 -06:00
|
|
|
|
|
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 one’s got an apostrophe'
|
2019-01-02 10:05:16 -06:00
|
|
|
|
'</span></a></p></li>')
|
2017-09-05 22:56:11 -05:00
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
2017-02-03 18:23:16 -06:00
|
|
|
|
|
|
|
|
|
# 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')
|
2017-02-03 18:23:16 -06:00
|
|
|
|
@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)
|
2017-11-26 08:02:36 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel',
|
2019-02-11 03:33:42 -06:00
|
|
|
|
confoverrides={'autosectionlabel_maxdepth': 3})
|
2019-02-11 03:07:57 -06:00
|
|
|
|
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()
|