2015-03-02 22:43:14 +09:00
|
|
|
"""Test sphinx.ext.ifconfig extension."""
|
|
|
|
|
|
2023-02-14 21:45:28 -08:00
|
|
|
import docutils.utils
|
2017-01-06 01:14:47 +09:00
|
|
|
import pytest
|
2015-03-02 22:43:14 +09:00
|
|
|
|
2023-02-14 21:45:28 -08:00
|
|
|
from sphinx import addnodes
|
|
|
|
|
from sphinx.testing import restructuredtext
|
|
|
|
|
|
2015-03-02 22:43:14 +09:00
|
|
|
|
2017-01-06 01:14:47 +09:00
|
|
|
@pytest.mark.sphinx('text', testroot='ext-ifconfig')
|
2015-03-02 22:43:14 +09:00
|
|
|
def test_ifconfig(app, status, warning):
|
2024-01-17 02:38:46 +00:00
|
|
|
app.build(force_all=True)
|
2022-04-27 03:04:19 +01:00
|
|
|
result = (app.outdir / 'index.txt').read_text(encoding='utf8')
|
2016-07-14 09:16:51 +09:00
|
|
|
assert 'spam' in result
|
|
|
|
|
assert 'ham' not in result
|
2023-02-14 21:45:28 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ifconfig_content_line_number(app):
|
|
|
|
|
app.setup_extension("sphinx.ext.ifconfig")
|
|
|
|
|
text = (".. ifconfig:: confval1\n" +
|
|
|
|
|
"\n" +
|
|
|
|
|
" Some link here: :ref:`abc`\n")
|
|
|
|
|
doc = restructuredtext.parse(app, text)
|
|
|
|
|
xrefs = list(doc.findall(condition=addnodes.pending_xref))
|
|
|
|
|
assert len(xrefs) == 1
|
|
|
|
|
source, line = docutils.utils.get_source_line(xrefs[0])
|
|
|
|
|
assert 'index.rst' in source
|
|
|
|
|
assert line == 3
|