File: test_unreferenced_footnotes.py

package info (click to toggle)
sphinx 8.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 26,712 kB
  • sloc: python: 105,846; javascript: 6,474; perl: 451; makefile: 178; sh: 37; xml: 19; ansic: 2
file content (50 lines) | stat: -rw-r--r-- 1,698 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Test the ``UnreferencedFootnotesDetector`` transform."""

from __future__ import annotations

from typing import TYPE_CHECKING

from sphinx._cli.util.errors import strip_escape_sequences
from sphinx.testing.util import SphinxTestApp

if TYPE_CHECKING:
    from pathlib import Path

    from sphinx.testing.util import SphinxTestApp


def test_warnings(make_app: type[SphinxTestApp], tmp_path: Path) -> None:
    """Test that warnings are emitted for unreferenced footnotes."""
    tmp_path.joinpath('conf.py').touch()
    tmp_path.joinpath('index.rst').write_text(
        """
Title
=====
[1]_ [#label2]_

.. [1] This is a normal footnote.
.. [2] This is a normal footnote.
.. [2] This is a normal footnote.
.. [3] This is a normal footnote.
.. [*] This is a symbol footnote.
.. [#] This is an auto-numbered footnote.
.. [#label1] This is an auto-numbered footnote with a label.
.. [#label1] This is an auto-numbered footnote with a label.
.. [#label2] This is an auto-numbered footnote with a label.
        """,
        encoding='utf8',
    )
    app = make_app(srcdir=tmp_path)
    app.build()
    warnings = strip_escape_sequences(app.warning.getvalue()).lstrip()
    warnings = warnings.replace(str(tmp_path / 'index.rst'), 'source/index.rst')
    assert (
        warnings
        == """\
source/index.rst:8: WARNING: Duplicate explicit target name: "2". [docutils]
source/index.rst:13: WARNING: Duplicate explicit target name: "label1". [docutils]
source/index.rst:9: WARNING: Footnote [3] is not referenced. [ref.footnote]
source/index.rst:10: WARNING: Footnote [*] is not referenced. [ref.footnote]
source/index.rst:11: WARNING: Footnote [#] is not referenced. [ref.footnote]
"""
    )