From 79c72ef53db147be011c0db8465aaad65f00251d Mon Sep 17 00:00:00 2001 From: Anthony Johnson Date: Mon, 6 Mar 2017 14:45:58 -0800 Subject: [PATCH 1/3] 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! --- .gitignore | 1 + .travis.yml | 11 +++ sphinx_rtd_theme/layout.html | 2 +- tests/__init__.py | 0 tests/roots/test-basic/bar.rst | 2 + tests/roots/test-basic/conf.py | 4 + tests/roots/test-basic/foo.rst | 6 ++ tests/roots/test-basic/index.rst | 12 +++ tests/roots/test-empty/conf.py | 4 + tests/roots/test-empty/index.rst | 10 +++ tests/roots/test-missing-toctree/conf.py | 4 + tests/roots/test-missing-toctree/index.rst | 2 + tests/test_builders.py | 99 ++++++++++++++++++++++ tests/util.py | 60 +++++++++++++ tox.ini | 21 +++++ 15 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 tests/__init__.py create mode 100644 tests/roots/test-basic/bar.rst create mode 100644 tests/roots/test-basic/conf.py create mode 100644 tests/roots/test-basic/foo.rst create mode 100644 tests/roots/test-basic/index.rst create mode 100644 tests/roots/test-empty/conf.py create mode 100644 tests/roots/test-empty/index.rst create mode 100644 tests/roots/test-missing-toctree/conf.py create mode 100644 tests/roots/test-missing-toctree/index.rst create mode 100644 tests/test_builders.py create mode 100644 tests/util.py create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 3076d7d..e612dcf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ .coverage *.DS_Store *.sass-cache +.ropeproject/ .ruby-version dist/ bower_components/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..abdeb38 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: python +python: + - 2.7 + - 3.4 + - 3.5 + - 3.6 +sudo: false +install: + - pip install tox-travis +script: + - tox diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html index 232a8f2..2221917 100644 --- a/sphinx_rtd_theme/layout.html +++ b/sphinx_rtd_theme/layout.html @@ -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 %} diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/roots/test-basic/bar.rst b/tests/roots/test-basic/bar.rst new file mode 100644 index 0000000..1cccd3c --- /dev/null +++ b/tests/roots/test-basic/bar.rst @@ -0,0 +1,2 @@ +bar +=== diff --git a/tests/roots/test-basic/conf.py b/tests/roots/test-basic/conf.py new file mode 100644 index 0000000..e10f5e5 --- /dev/null +++ b/tests/roots/test-basic/conf.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +master_doc = 'index' +exclude_patterns = ['_build'] diff --git a/tests/roots/test-basic/foo.rst b/tests/roots/test-basic/foo.rst new file mode 100644 index 0000000..468a424 --- /dev/null +++ b/tests/roots/test-basic/foo.rst @@ -0,0 +1,6 @@ +foo +=== + +.. toctree:: + + bar diff --git a/tests/roots/test-basic/index.rst b/tests/roots/test-basic/index.rst new file mode 100644 index 0000000..0a4b347 --- /dev/null +++ b/tests/roots/test-basic/index.rst @@ -0,0 +1,12 @@ +test-basic +========== + +.. toctree:: + + foo + +Heading +------- + +Subheading +~~~~~~~~~~ diff --git a/tests/roots/test-empty/conf.py b/tests/roots/test-empty/conf.py new file mode 100644 index 0000000..e10f5e5 --- /dev/null +++ b/tests/roots/test-empty/conf.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +master_doc = 'index' +exclude_patterns = ['_build'] diff --git a/tests/roots/test-empty/index.rst b/tests/roots/test-empty/index.rst new file mode 100644 index 0000000..a69c08d --- /dev/null +++ b/tests/roots/test-empty/index.rst @@ -0,0 +1,10 @@ +test-empty +========== + +.. toctree:: + +Heading +------- + +Subheading +~~~~~~~~~~ diff --git a/tests/roots/test-missing-toctree/conf.py b/tests/roots/test-missing-toctree/conf.py new file mode 100644 index 0000000..e10f5e5 --- /dev/null +++ b/tests/roots/test-missing-toctree/conf.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +master_doc = 'index' +exclude_patterns = ['_build'] diff --git a/tests/roots/test-missing-toctree/index.rst b/tests/roots/test-missing-toctree/index.rst new file mode 100644 index 0000000..a085e7f --- /dev/null +++ b/tests/roots/test-missing-toctree/index.rst @@ -0,0 +1,2 @@ +test-missing-toctree +==================== diff --git a/tests/test_builders.py b/tests/test_builders.py new file mode 100644 index 0000000..3602782 --- /dev/null +++ b/tests/test_builders.py @@ -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 = ( + '
\n' + '\n' + '
' + ) + assert search in content + elif isinstance(app.builder, SingleFileHTMLBuilder): + search = ( + '