sphinx/tests/test_toctree.py
Anthony Johnson 3390b7f499
Allow empty toctree in singlehtml builder
We noticed this issue with the 0.2.x release of snide/sphinx_rtd_theme. Because
we are calling toctree unconditionally, we notice a bug in the singlehtml
builder when the docs have an empty/nonexistant toctree. In this case,
`fix_refuris` as being passed `None`, which failed to traverse, throwing an
exception.

This conditionally fixes the refuris instead.
2017-03-05 13:31:43 -08:00

39 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
"""
test_toctree
~~~~~~~~~~~~
Test the HTML builder and check output against XPath.
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import pytest
@pytest.mark.sphinx(testroot='toctree-glob')
def test_relations(app, status, warning):
app.builder.build_all()
assert app.builder.relations['index'] == [None, None, 'foo']
assert app.builder.relations['foo'] == ['index', 'index', 'bar/index']
assert app.builder.relations['bar/index'] == ['index', 'foo', 'bar/bar_1']
assert app.builder.relations['bar/bar_1'] == ['bar/index', 'bar/index', 'bar/bar_2']
assert app.builder.relations['bar/bar_2'] == ['bar/index', 'bar/bar_1', 'bar/bar_3']
assert app.builder.relations['bar/bar_3'] == ['bar/index', 'bar/bar_2', 'bar/bar_4/index']
assert app.builder.relations['bar/bar_4/index'] == ['bar/index', 'bar/bar_3', 'baz']
assert app.builder.relations['baz'] == ['index', 'bar/bar_4/index', 'qux/index']
assert app.builder.relations['qux/index'] == ['index', 'baz', 'qux/qux_1']
assert app.builder.relations['qux/qux_1'] == ['qux/index', 'qux/index', 'qux/qux_2']
assert app.builder.relations['qux/qux_2'] == ['qux/index', 'qux/qux_1', None]
assert 'quux' not in app.builder.relations
@pytest.mark.sphinx('singlehtml', testroot='toctree-empty')
def test_singlehtml_toctree(app, status, warning):
docname = 'index'
app.builder.build_all()
try:
app.builder._get_local_toctree('index')
except AttributeError:
pytest.fail('Unexpected AttributeError in app.builder.fix_refuris')