1""" 2 test_toctree 3 ~~~~~~~~~~~~ 4 5 Test the HTML builder and check output against XPath. 6 7 :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. 8 :license: BSD, see LICENSE for details. 9""" 10import re 11 12import pytest 13 14 15@pytest.mark.sphinx(testroot='toctree-glob') 16def test_relations(app, status, warning): 17 app.builder.build_all() 18 assert app.builder.relations['index'] == [None, None, 'foo'] 19 assert app.builder.relations['foo'] == ['index', 'index', 'bar/index'] 20 assert app.builder.relations['bar/index'] == ['index', 'foo', 'bar/bar_1'] 21 assert app.builder.relations['bar/bar_1'] == ['bar/index', 'bar/index', 'bar/bar_2'] 22 assert app.builder.relations['bar/bar_2'] == ['bar/index', 'bar/bar_1', 'bar/bar_3'] 23 assert app.builder.relations['bar/bar_3'] == ['bar/index', 'bar/bar_2', 'bar/bar_4/index'] 24 assert app.builder.relations['bar/bar_4/index'] == ['bar/index', 'bar/bar_3', 'baz'] 25 assert app.builder.relations['baz'] == ['index', 'bar/bar_4/index', 'qux/index'] 26 assert app.builder.relations['qux/index'] == ['index', 'baz', 'qux/qux_1'] 27 assert app.builder.relations['qux/qux_1'] == ['qux/index', 'qux/index', 'qux/qux_2'] 28 assert app.builder.relations['qux/qux_2'] == ['qux/index', 'qux/qux_1', None] 29 assert 'quux' not in app.builder.relations 30 31 32@pytest.mark.sphinx('singlehtml', testroot='toctree-empty') 33def test_singlehtml_toctree(app, status, warning): 34 app.builder.build_all() 35 try: 36 app.builder._get_local_toctree('index') 37 except AttributeError: 38 pytest.fail('Unexpected AttributeError in app.builder.fix_refuris') 39 40 41@pytest.mark.sphinx(testroot='toctree', srcdir="numbered-toctree") 42def test_numbered_toctree(app, status, warning): 43 # give argument to :numbered: option 44 index = (app.srcdir / 'index.rst').read_text() 45 index = re.sub(':numbered:.*', ':numbered: 1', index) 46 (app.srcdir / 'index.rst').write_text(index) 47 app.builder.build_all() 48