Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/roots/test-refuris/ch1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Chapter One
===========

This chapter discusses :term:`API` design and :term:`REST` principles.

We use :term:`API` throughout our application to communicate between
different services.

Section 1.1
-----------

More details about :term:`REST` architecture here.

The :term:`API` should follow RESTful conventions.
2 changes: 2 additions & 0 deletions tests/roots/test-refuris/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
project = 'Glossary Test'
extensions = []
4 changes: 4 additions & 0 deletions tests/roots/test-refuris/glossary/term1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. glossary::

API
Lorem Ipsum.
4 changes: 4 additions & 0 deletions tests/roots/test-refuris/glossary/term2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. glossary::

API
Lorem Ipsum.
11 changes: 11 additions & 0 deletions tests/roots/test-refuris/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Main Documentation
==================

Welcome to the documentation.

.. toctree::
:maxdepth: 2

ch1
glossary/term1
glossary/term2
42 changes: 42 additions & 0 deletions tests/test_builders/test_build_html_refuris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Test output of reference URIs when building single-page HTML output."""

from __future__ import annotations

from typing import TYPE_CHECKING

import pytest

from tests.test_builders.xpath_util import check_xpath

if TYPE_CHECKING:
from collections.abc import Callable, Sequence
from pathlib import Path
from xml.etree.ElementTree import Element, ElementTree

from sphinx.testing.util import SphinxTestApp


def _internal_reference_fragment_check(nodes: Sequence[Element]) -> None:
"""Confirm that internal references do not contain duplicate fragment symbols"""
assert nodes, 'Expected at least one node to check'
for node in nodes:
assert node.tag == 'a', 'Attempted to check hyperlink on a non-anchor element'
href = node.attrib.get('href')
# Allow Sphinx index and table hyperlinks to be non-same-document, as exceptions.
if href in {'genindex.html', 'py-modindex.html', 'search.html'}:
continue
assert not href or href.count('#') < 2, 'Hyperlink contains duplicate fragments'


@pytest.mark.sphinx('singlehtml', testroot='refuris')
def test_singlehtml_refuris(
app: SphinxTestApp,
cached_etree_parse: Callable[[Path], ElementTree],
) -> None:
app.build()
check_xpath(
cached_etree_parse(app.outdir / 'index.html'),
'index.html',
".//a[@class='reference internal']",
_internal_reference_fragment_check,
)
Loading