2016-02-14 16:07:32 +09:00
|
|
|
|
"""
|
|
|
|
|
|
test_ext_autosectionlabel
|
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
|
|
Test sphinx.ext.autosectionlabel extension.
|
|
|
|
|
|
|
2019-01-02 16:00:30 +09:00
|
|
|
|
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
|
2016-02-14 16:07:32 +09:00
|
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
2017-01-06 01:14:47 +09:00
|
|
|
|
import pytest
|
2016-02-14 16:07:32 +09:00
|
|
|
|
|
2019-01-03 01:05:16 +09:00
|
|
|
|
from sphinx.util import docutils
|
2016-02-14 16:07:32 +09:00
|
|
|
|
|
2019-01-03 01:05:16 +09:00
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(docutils.__version_info__ < (0, 13),
|
|
|
|
|
|
reason='docutils-0.13 or above is required')
|
2017-01-06 01:14:47 +09:00
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel')
|
2017-11-26 18:02:36 +04:00
|
|
|
|
def test_autosectionlabel_html(app, status, warning, skipped_labels=False):
|
2016-02-14 16:07:32 +09:00
|
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
|
|
|
|
content = (app.outdir / 'index.html').text()
|
2019-01-03 01:05:16 +09:00
|
|
|
|
html = ('<li><p><a class="reference internal" href="#introduce-of-sphinx">'
|
|
|
|
|
|
'<span class=".*?">Introduce of Sphinx</span></a></p></li>')
|
2016-02-14 16:07:32 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
2019-01-03 01:05:16 +09:00
|
|
|
|
html = ('<li><p><a class="reference internal" href="#installation">'
|
|
|
|
|
|
'<span class="std std-ref">Installation</span></a></p></li>')
|
2016-02-14 16:07:32 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
2019-01-03 01:05:16 +09: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 16:07:32 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
2019-01-03 01:05:16 +09: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 16:07:32 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
2017-02-04 01:23:16 +01:00
|
|
|
|
|
2019-02-14 02:04:21 +09:00
|
|
|
|
html = ('<li><p><a class="reference internal" href="#linux">'
|
|
|
|
|
|
'<span class="std std-ref">Linux</span></a></p></li>')
|
2019-02-11 18:34:04 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
2017-11-26 18:02:36 +04:00
|
|
|
|
|
2019-02-14 02:04:21 +09:00
|
|
|
|
html = ('<li><p><a class="reference internal" href="#freebsd">'
|
|
|
|
|
|
'<span class="std std-ref">FreeBSD</span></a></p></li>')
|
2019-02-11 18:34:04 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
2017-11-26 18:02:36 +04:00
|
|
|
|
|
2018-02-11 13:54:47 +09:00
|
|
|
|
# for smart_quotes (refs: #4027)
|
2019-01-03 01:05:16 +09:00
|
|
|
|
html = ('<li><p><a class="reference internal" '
|
2018-12-15 23:02:28 +09:00
|
|
|
|
'href="#this-one-s-got-an-apostrophe">'
|
|
|
|
|
|
'<span class="std std-ref">This one’s got an apostrophe'
|
2019-01-03 01:05:16 +09:00
|
|
|
|
'</span></a></p></li>')
|
2017-09-05 21:56:11 -06:00
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
2017-02-04 01:23:16 +01:00
|
|
|
|
|
|
|
|
|
|
# Re-use test definition from above, just change the test root directory
|
2019-01-03 01:05:16 +09:00
|
|
|
|
@pytest.mark.skipif(docutils.__version_info__ < (0, 13),
|
|
|
|
|
|
reason='docutils-0.13 or above is required')
|
2017-02-04 01:23:16 +01:00
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel-prefix-document')
|
|
|
|
|
|
def test_autosectionlabel_prefix_document_html(app, status, warning):
|
2019-02-11 18:34:04 +09:00
|
|
|
|
test_autosectionlabel_html(app, status, warning)
|
2017-11-26 18:02:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
2019-02-14 02:04:21 +09:00
|
|
|
|
@pytest.mark.skipif(docutils.__version_info__ < (0, 13),
|
|
|
|
|
|
reason='docutils-0.13 or above is required')
|
2017-11-26 18:02:36 +04:00
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel',
|
2019-02-11 18:33:42 +09:00
|
|
|
|
confoverrides={'autosectionlabel_maxdepth': 3})
|
2019-02-11 18:07:57 +09:00
|
|
|
|
def test_autosectionlabel_maxdepth(app, status, warning):
|
2019-02-11 18:34:04 +09:00
|
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
|
|
|
|
content = (app.outdir / 'index.html').text()
|
|
|
|
|
|
|
|
|
|
|
|
# depth: 1
|
2019-02-14 02:04:21 +09:00
|
|
|
|
html = ('<li><p><a class="reference internal" href="#test-ext-autosectionlabel">'
|
|
|
|
|
|
'<span class=".*?">test-ext-autosectionlabel</span></a></p></li>')
|
2019-02-11 18:34:04 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
|
|
|
|
|
# depth: 2
|
2019-02-14 02:04:21 +09:00
|
|
|
|
html = ('<li><p><a class="reference internal" href="#installation">'
|
|
|
|
|
|
'<span class="std std-ref">Installation</span></a></p></li>')
|
2019-02-11 18:34:04 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
|
|
|
|
|
# depth: 3
|
2019-02-14 02:04:21 +09:00
|
|
|
|
html = ('<li><p><a class="reference internal" href="#for-windows-users">'
|
|
|
|
|
|
'<span class="std std-ref">For Windows users</span></a></p></li>')
|
2019-02-11 18:34:04 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
|
|
|
|
|
# depth: 4
|
2019-02-14 02:04:21 +09:00
|
|
|
|
html = '<li><p><span class="xref std std-ref">Linux</span></p></li>'
|
2019-02-11 18:34:04 +09:00
|
|
|
|
assert re.search(html, content, re.S)
|
|
|
|
|
|
|
|
|
|
|
|
assert 'WARNING: undefined label: linux' in warning.getvalue()
|