Skip to content

Commit 1da0839

Browse files
committed
Add test to assert unique ids in singlehtml output
Since the singlehtml aggregates all doc files into a single html page during the write step, and the ids must be unique for proper link anchoring, add test that collects all ids in the page and checks if all ids are unique, by asserting the length of the list against it as a set.
1 parent f5457f1 commit 1da0839

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/test_builders/test_build_html_tocdepth.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,16 @@ def test_tocdepth_singlehtml(
134134
) -> None:
135135
app.build()
136136
check_xpath(cached_etree_parse(app.outdir / 'index.html'), 'index.html', *expect)
137+
138+
@pytest.mark.sphinx('singlehtml', testroot='tocdepth')
139+
@pytest.mark.test_params(shared_result='test_build_html_tocdepth')
140+
def test_unique_ids_singlehtml(
141+
app: SphinxTestApp,
142+
cached_etree_parse: Callable[[Path], ElementTree],
143+
) -> None:
144+
app.build()
145+
tree = cached_etree_parse(app.outdir / 'index.html')
146+
root = tree.getroot()
147+
148+
ids = [el.attrib['id'] for el in root.findall(".//*[@id]")]
149+
assert len(ids) == len(set(ids))

0 commit comments

Comments
 (0)