| 1 |
"""Test the ``UnreferencedFootnotesDetector`` transform.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from typing import TYPE_CHECKING |
| 6 |
|
| 7 |
from sphinx._cli.util.errors import strip_escape_sequences |
| 8 |
from sphinx.testing.util import SphinxTestApp |
| 9 |
|
| 10 |
if TYPE_CHECKING: |
| 11 |
from pathlib import Path |
| 12 |
|
| 13 |
from sphinx.testing.util import SphinxTestApp |
| 14 |
|
| 15 |
|
| 16 |
def test_warnings(make_app: type[SphinxTestApp], tmp_path: Path) -> None: |
| 17 |
"""Test that warnings are emitted for unreferenced footnotes.""" |
| 18 |
tmp_path.joinpath('conf.py').touch() |
| 19 |
tmp_path.joinpath('index.rst').write_text( |
| 20 |
""" |
| 21 |
Title |
| 22 |
===== |
| 23 |
[1]_ [#label2]_ |
| 24 |
|
| 25 |
.. [1] This is a normal footnote. |
| 26 |
.. [2] This is a normal footnote. |
| 27 |
.. [2] This is a normal footnote. |
| 28 |
.. [3] This is a normal footnote. |
| 29 |
.. [*] This is a symbol footnote. |
| 30 |
.. [#] This is an auto-numbered footnote. |
| 31 |
.. [#label1] This is an auto-numbered footnote with a label. |
| 32 |
.. [#label1] This is an auto-numbered footnote with a label. |
| 33 |
.. [#label2] This is an auto-numbered footnote with a label. |
| 34 |
""", |
| 35 |
encoding='utf8', |
| 36 |
) |
| 37 |
app = make_app(srcdir=tmp_path) |
| 38 |
app.build() |
| 39 |
warnings = strip_escape_sequences(app.warning.getvalue()).lstrip() |
| 40 |
warnings = warnings.replace(str(tmp_path / 'index.rst'), 'source/index.rst') |
| 41 |
assert ( |
| 42 |
warnings |
| 43 |
== """\ |
| 44 |
source/index.rst:8: WARNING: Duplicate explicit target name: "2". [docutils] |
| 45 |
source/index.rst:13: WARNING: Duplicate explicit target name: "label1". [docutils] |
| 46 |
source/index.rst:9: WARNING: Footnote [3] is not referenced. [ref.footnote] |
| 47 |
source/index.rst:10: WARNING: Footnote [*] is not referenced. [ref.footnote] |
| 48 |
source/index.rst:11: WARNING: Footnote [#] is not referenced. [ref.footnote] |
| 49 |
""" |
| 50 |
) |