Debian Codegraph @

tests/test_extensions/test_ext_ifconfig.py

raw
1 """Test sphinx.ext.ifconfig extension."""
2
3 from __future__ import annotations
4
5 from typing import TYPE_CHECKING
6
7 import docutils.utils
8 import pytest
9
10 from sphinx import addnodes
11 from sphinx.testing import restructuredtext
12
13 if TYPE_CHECKING:
14 from sphinx.testing.util import SphinxTestApp
15
16
17 @pytest.mark.sphinx('text', testroot='ext-ifconfig')
18 def test_ifconfig(app: SphinxTestApp) -> None:
19 app.build(force_all=True)
20 result = (app.outdir / 'index.txt').read_text(encoding='utf8')
21 assert 'spam' in result
22 assert 'ham' not in result
23
24
25 @pytest.mark.sphinx('html', testroot='_blank')
26 def test_ifconfig_content_line_number(app: SphinxTestApp) -> None:
27 app.setup_extension('sphinx.ext.ifconfig')
28 text = '.. ifconfig:: confval1\n\n Some link here: :ref:`abc`\n'
29 doc = restructuredtext.parse(app, text)
30 xrefs = list(doc.findall(condition=addnodes.pending_xref))
31 assert len(xrefs) == 1
32 source, line = docutils.utils.get_source_line(xrefs[0])
33 assert 'index.rst' in source
34 assert line == 3