refactor tests for autosectionlabel

This commit is contained in:
Takeshi KOMIYA 2019-02-11 18:34:04 +09:00
parent 2d44232e34
commit ac399b3b4e
3 changed files with 40 additions and 23 deletions

View File

@ -15,6 +15,12 @@ For Windows users
For UNIX users
--------------
Linux
^^^^^
FreeBSD
^^^^^^^
This one's got an apostrophe
----------------------------
@ -26,4 +32,6 @@ References
* :ref:`index:Installation`
* :ref:`index:For Windows users`
* :ref:`index:For UNIX users`
* :ref:`index:Linux`
* :ref:`index:FreeBSD`
* :ref:`index:This one's got an apostrophe`

View File

@ -27,6 +27,7 @@ This one's got an apostrophe
References
==========
* :ref:`test-ext-autosectionlabel`
* :ref:`Introduce of Sphinx`
* :ref:`Installation`
* :ref:`For Windows users`

View File

@ -34,26 +34,13 @@ def test_autosectionlabel_html(app, status, warning, skipped_labels=False):
'<span class="std std-ref">For UNIX users</span></a></li>')
assert re.search(html, content, re.S)
if skipped_labels is None:
return
html = ('<li><a class="reference internal" href="#linux">'
'<span class="std std-ref">Linux</span></a></li>')
assert re.search(html, content, re.S)
if not skipped_labels:
html = ('<li><a class="reference internal" href="#linux">'
'<span class="std std-ref">Linux</span></a></li>')
assert re.search(html, content, re.S)
html = ('<li><a class="reference internal" href="#freebsd">'
'<span class="std std-ref">FreeBSD</span></a></li>')
assert re.search(html, content, re.S)
else:
html = '<li><span class="xref std std-ref">Linux</span></li>'
assert re.search(html, content, re.S)
html = '<li><span class="xref std std-ref">FreeBSD</span></li>'
assert re.search(html, content, re.S)
assert 'WARNING: undefined label: linux' in warning.getvalue()
assert 'WARNING: undefined label: freebsd' in warning.getvalue()
html = ('<li><a class="reference internal" href="#freebsd">'
'<span class="std std-ref">FreeBSD</span></a></li>')
assert re.search(html, content, re.S)
# for smart_quotes (refs: #4027)
html = ('<li><a class="reference internal" '
@ -66,12 +53,33 @@ def test_autosectionlabel_html(app, status, warning, skipped_labels=False):
# Re-use 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, status, warning):
return test_autosectionlabel_html(app, status, warning,
skipped_labels=None)
test_autosectionlabel_html(app, status, warning)
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel',
confoverrides={'autosectionlabel_maxdepth': 3})
def test_autosectionlabel_maxdepth(app, status, warning):
return test_autosectionlabel_html(app, status, warning,
skipped_labels=True)
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()