mirror of
https://github.com/readthedocs/sphinx_rtd_theme.git
synced 2025-02-25 18:55:21 -06:00
Adds testing and hopefully a final fix for the empty toctree issue
This adds some more hacky fixes to our layout to avoid singlehtml builders. Instead of trying to guess if this is working, I added testing!
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@
|
||||
.coverage
|
||||
*.DS_Store
|
||||
*.sass-cache
|
||||
.ropeproject/
|
||||
.ruby-version
|
||||
dist/
|
||||
bower_components/
|
||||
|
||||
11
.travis.yml
Normal file
11
.travis.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
language: python
|
||||
python:
|
||||
- 2.7
|
||||
- 3.4
|
||||
- 3.5
|
||||
- 3.6
|
||||
sudo: false
|
||||
install:
|
||||
- pip install tox-travis
|
||||
script:
|
||||
- tox
|
||||
@@ -129,7 +129,7 @@
|
||||
The singlehtml builder doesn't handle this toctree call when the
|
||||
toctree is empty. Skip building this for now.
|
||||
#}
|
||||
{% if builder != 'singlehtml' %}
|
||||
{% if builder not in ['singlehtml', 'readthedocssinglehtml', 'readthedocssinglehtmllocalmedia'] %}
|
||||
{% set global_toc = toctree(maxdepth=theme_navigation_depth|int, collapse=theme_collapse_navigation, includehidden=True) %}
|
||||
{% endif %}
|
||||
{% if global_toc %}
|
||||
|
||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
2
tests/roots/test-basic/bar.rst
Normal file
2
tests/roots/test-basic/bar.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
bar
|
||||
===
|
||||
4
tests/roots/test-basic/conf.py
Normal file
4
tests/roots/test-basic/conf.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
master_doc = 'index'
|
||||
exclude_patterns = ['_build']
|
||||
6
tests/roots/test-basic/foo.rst
Normal file
6
tests/roots/test-basic/foo.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
foo
|
||||
===
|
||||
|
||||
.. toctree::
|
||||
|
||||
bar
|
||||
12
tests/roots/test-basic/index.rst
Normal file
12
tests/roots/test-basic/index.rst
Normal file
@@ -0,0 +1,12 @@
|
||||
test-basic
|
||||
==========
|
||||
|
||||
.. toctree::
|
||||
|
||||
foo
|
||||
|
||||
Heading
|
||||
-------
|
||||
|
||||
Subheading
|
||||
~~~~~~~~~~
|
||||
4
tests/roots/test-empty/conf.py
Normal file
4
tests/roots/test-empty/conf.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
master_doc = 'index'
|
||||
exclude_patterns = ['_build']
|
||||
10
tests/roots/test-empty/index.rst
Normal file
10
tests/roots/test-empty/index.rst
Normal file
@@ -0,0 +1,10 @@
|
||||
test-empty
|
||||
==========
|
||||
|
||||
.. toctree::
|
||||
|
||||
Heading
|
||||
-------
|
||||
|
||||
Subheading
|
||||
~~~~~~~~~~
|
||||
4
tests/roots/test-missing-toctree/conf.py
Normal file
4
tests/roots/test-missing-toctree/conf.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
master_doc = 'index'
|
||||
exclude_patterns = ['_build']
|
||||
2
tests/roots/test-missing-toctree/index.rst
Normal file
2
tests/roots/test-missing-toctree/index.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
test-missing-toctree
|
||||
====================
|
||||
99
tests/test_builders.py
Normal file
99
tests/test_builders.py
Normal file
@@ -0,0 +1,99 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
import sphinx
|
||||
from sphinx import addnodes
|
||||
from sphinx.builders.html import SingleFileHTMLBuilder, DirectoryHTMLBuilder
|
||||
|
||||
from .util import build_all
|
||||
|
||||
|
||||
def test_basic():
|
||||
for (app, status, warning) in build_all('test-basic'):
|
||||
assert app.env.get_doctree('index').traverse(addnodes.toctree)
|
||||
content = open(os.path.join(app.outdir, 'index.html')).read()
|
||||
|
||||
if isinstance(app.builder, DirectoryHTMLBuilder):
|
||||
search = (
|
||||
'<div class="toctree-wrapper compound">\n'
|
||||
'<ul>\n'
|
||||
'<li class="toctree-l1">'
|
||||
'<a class="reference internal" href="foo/">foo</a>'
|
||||
'<ul>\n'
|
||||
'<li class="toctree-l2">'
|
||||
'<a class="reference internal" href="bar/">bar</a></li>\n'
|
||||
'</ul>\n'
|
||||
'</li>\n'
|
||||
'</ul>\n'
|
||||
'</div>'
|
||||
)
|
||||
assert search in content
|
||||
elif isinstance(app.builder, SingleFileHTMLBuilder):
|
||||
search = (
|
||||
'<div class="local-toc"><ul>\n'
|
||||
'<li class="toctree-l1">'
|
||||
'<a class="reference internal" href="index.html#document-foo">foo</a>'
|
||||
'<ul>\n'
|
||||
'<li class="toctree-l2">'
|
||||
'<a class="reference internal" href="index.html#document-bar">bar</a>'
|
||||
'</li>\n'
|
||||
'</ul>'
|
||||
)
|
||||
assert search in content
|
||||
else:
|
||||
search = (
|
||||
'<div class="toctree-wrapper compound">\n'
|
||||
'<ul>\n'
|
||||
'<li class="toctree-l1">'
|
||||
'<a class="reference internal" href="foo.html">foo</a>'
|
||||
'<ul>\n'
|
||||
'<li class="toctree-l2">'
|
||||
'<a class="reference internal" href="bar.html">bar</a></li>\n'
|
||||
'</ul>\n'
|
||||
'</li>\n'
|
||||
'</ul>\n'
|
||||
'</div>'
|
||||
)
|
||||
assert search in content, ('Missing search with builder {0}'
|
||||
.format(app.builder.name))
|
||||
|
||||
|
||||
def test_empty():
|
||||
"""Local TOC is showing, as toctree was empty"""
|
||||
for (app, status, warning) in build_all('test-empty'):
|
||||
assert app.env.get_doctree('index').traverse(addnodes.toctree)
|
||||
content = open(os.path.join(app.outdir, 'index.html')).read()
|
||||
if sphinx.version_info < (1, 4):
|
||||
if isinstance(app.builder, SingleFileHTMLBuilder):
|
||||
assert '<div class="toctree-wrapper compound">\n</div>' in content
|
||||
assert '<div class="local-toc">' in content
|
||||
else:
|
||||
global_toc = (
|
||||
'<div class="toctree-wrapper compound">\n'
|
||||
'<ul class="simple">\n</ul>\n'
|
||||
'</div>'
|
||||
)
|
||||
local_toc = (
|
||||
'<div class="local-toc"><ul class="simple">'
|
||||
'</ul>\n</div>'
|
||||
)
|
||||
assert global_toc in content
|
||||
assert local_toc not in content
|
||||
else:
|
||||
global_toc = '<div class="toctree-wrapper compound">\n</div>'
|
||||
local_toc = (
|
||||
'<div class="local-toc"><ul>\n'
|
||||
'<li><a class="reference internal" href="#">test-empty</a></li>'
|
||||
'</ul>\n</div>'
|
||||
)
|
||||
assert global_toc in content
|
||||
assert local_toc not in content
|
||||
|
||||
|
||||
def test_missing_toctree():
|
||||
"""Local TOC is showing, as toctree was missing"""
|
||||
for (app, status, warning) in build_all('test-missing-toctree'):
|
||||
assert app.env.get_doctree('index').traverse(addnodes.toctree) == []
|
||||
content = open(os.path.join(app.outdir, 'index.html')).read()
|
||||
assert '<div class="toctree' not in content
|
||||
assert '<div class="local-toc">' in content
|
||||
60
tests/util.py
Normal file
60
tests/util.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
from contextlib import contextmanager
|
||||
|
||||
import pytest
|
||||
from sphinx.application import Sphinx
|
||||
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
|
||||
|
||||
@contextmanager
|
||||
def build(root, builder='html', **kwargs):
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
|
||||
srcdir = os.path.join(os.path.dirname(__file__), 'roots', root)
|
||||
destdir = os.path.join(tmpdir, builder)
|
||||
doctreedir = os.path.join(tmpdir, 'doctree/')
|
||||
|
||||
status = StringIO()
|
||||
warning = StringIO()
|
||||
|
||||
kwargs.update({
|
||||
'status': status,
|
||||
'warning': warning,
|
||||
})
|
||||
|
||||
confoverrides = kwargs.pop('confoverrides', {})
|
||||
confoverrides['html_theme'] = 'sphinx_rtd_theme'
|
||||
extensions = confoverrides.get('extensions', [])
|
||||
extensions.append('readthedocs_ext.readthedocs')
|
||||
confoverrides['extensions'] = extensions
|
||||
kwargs['confoverrides'] = confoverrides
|
||||
|
||||
try:
|
||||
app = Sphinx(srcdir, srcdir, destdir, doctreedir, builder, **kwargs)
|
||||
app.builder.build_all()
|
||||
yield (app, status.getvalue(), warning.getvalue())
|
||||
except Exception as e:
|
||||
print('# root:', root)
|
||||
print('# builder:', builder)
|
||||
print('# source:', srcdir)
|
||||
print('# destination:', destdir)
|
||||
print('# status:', '\n' + status.getvalue())
|
||||
print('# warning:', '\n' + warning.getvalue())
|
||||
raise
|
||||
finally:
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
|
||||
def build_all(root, **kwargs):
|
||||
for builder in ['html', 'singlehtml', 'readthedocs', 'readthedocsdirhtml',
|
||||
'readthedocssinglehtml', 'readthedocssinglehtmllocalmedia']:
|
||||
with build(root, builder, **kwargs) as ret:
|
||||
yield ret
|
||||
21
tox.ini
Normal file
21
tox.ini
Normal file
@@ -0,0 +1,21 @@
|
||||
[tox]
|
||||
envlist = py{27,34,35,36}-sphinx{13,14,15}
|
||||
|
||||
[tox:travis]
|
||||
2.7 = py27-sphinx{13,14,15}
|
||||
3.4 = py34-sphinx{13,14,15}
|
||||
3.5 = py35-sphinx{13,14,15}
|
||||
3.6 = py36-sphinx{13,14,15}
|
||||
|
||||
[testenv]
|
||||
setev =
|
||||
LANG=C
|
||||
deps =
|
||||
.
|
||||
readthedocs-sphinx-ext
|
||||
pytest
|
||||
sphinx13: Sphinx < 1.4
|
||||
sphinx14: Sphinx < 1.5
|
||||
sphinx15: Sphinx < 1.6
|
||||
commands =
|
||||
py.test {posargs}
|
||||
Reference in New Issue
Block a user