Skip to content

Commit bdeb4e0

Browse files
committed
Add tests and update CHANGES
1 parent eac87fd commit bdeb4e0

File tree

9 files changed

+61
-0
lines changed

9 files changed

+61
-0
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ Bugs fixed
9999
* #12796: Enable parallel reading if requested,
100100
even if there are fewer than 6 documents.
101101
Patch by Matthias Geier.
102+
* #12888: Ensure deterministic resolution of global toctree in parallel builds
103+
when document is included in multiple toctrees by choosing lexicographically
104+
greatest parent document.
105+
Patch by A. Rafey Khan
102106

103107

104108
Testing
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Bar
2+
===
3+
.. literalinclude:: relation_graph.txt
4+
5+
.. toctree::
6+
qux
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Baz
2+
===
3+
.. literalinclude:: relation_graph.txt
4+
5+
.. toctree::
6+
qux

tests/roots/test-toctree-multiple-parents/conf.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Foo
2+
===
3+
.. literalinclude:: relation_graph.txt
4+
5+
.. toctree::
6+
bar
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test-toctree-multiple-parents
2+
=============================
3+
.. literalinclude:: relation_graph.txt
4+
5+
.. toctree::
6+
foo
7+
baz
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Qux
2+
===
3+
.. literalinclude:: relation_graph.txt
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
index
2+
/ \
3+
foo baz
4+
\ /
5+
bar /
6+
\ /
7+
qux

tests/test_builders/test_build_html_toctree.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44

55
import pytest
6+
from unittest.mock import patch
67

78
from tests.test_builders.xpath_html_util import _intradocument_hyperlink_check
89
from tests.test_builders.xpath_util import check_xpath
@@ -63,3 +64,24 @@ def test_numbered_toctree(app):
6364
def test_singlehtml_hyperlinks(app, cached_etree_parse, expect):
6465
app.build()
6566
check_xpath(cached_etree_parse(app.outdir / 'index.html'), 'index.html', *expect)
67+
68+
@pytest.mark.sphinx(
69+
'html',
70+
testroot='toctree-multiple-parents',
71+
confoverrides={'html_theme': 'alabaster'}
72+
)
73+
def test_toctree_multiple_parents(app, cached_etree_parse):
74+
# Lexicographically greatest parent of the document in global toctree
75+
# should be chosen regardless of the order in which files are read
76+
with patch.object(app.builder, '_read_serial') as mock_read_serial:
77+
# Read files in reversed order
78+
_read_serial = app.builder.__class__._read_serial
79+
mock_read_serial.side_effect = lambda docnames: _read_serial(
80+
app.builder,
81+
list(reversed(docnames))
82+
)
83+
app.build()
84+
# Check if qux is a child of baz in qux.html
85+
xpath_baz_children = ".//ul[@class='current']//a[@href='baz.html']/../ul/li//a"
86+
etree = cached_etree_parse(app.outdir / 'qux.html')
87+
check_xpath(etree, 'qux.html', xpath=xpath_baz_children, check="Qux")

0 commit comments

Comments
 (0)