|
3 | 3 | import re |
4 | 4 |
|
5 | 5 | import pytest |
| 6 | +from unittest.mock import patch |
6 | 7 |
|
7 | 8 | from tests.test_builders.xpath_html_util import _intradocument_hyperlink_check |
8 | 9 | from tests.test_builders.xpath_util import check_xpath |
@@ -63,3 +64,24 @@ def test_numbered_toctree(app): |
63 | 64 | def test_singlehtml_hyperlinks(app, cached_etree_parse, expect): |
64 | 65 | app.build() |
65 | 66 | 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