summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:56:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:56:50 +0000
commit6637322c8ab1c5ff80a2b6ca59c9ba1d40aeba2c (patch)
tree04e41667e9eae835f5d88bda4f6d3f5c2664de01 /tests
parentInitial commit. (diff)
downloadsphinx-rtd-theme-6637322c8ab1c5ff80a2b6ca59c9ba1d40aeba2c.tar.xz
sphinx-rtd-theme-6637322c8ab1c5ff80a2b6ca59c9ba1d40aeba2c.zip
Adding upstream version 2.0.0+dfsg.upstream/2.0.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/roots/test-basic/bar.rst2
-rw-r--r--tests/roots/test-basic/conf.py4
-rw-r--r--tests/roots/test-basic/foo.rst6
-rw-r--r--tests/roots/test-basic/index.rst12
-rw-r--r--tests/roots/test-empty/conf.py4
-rw-r--r--tests/roots/test-empty/index.rst10
-rw-r--r--tests/roots/test-missing-toctree/conf.py4
-rw-r--r--tests/roots/test-missing-toctree/index.rst2
-rw-r--r--tests/test_builders.py87
-rw-r--r--tests/util.py61
11 files changed, 192 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
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..d3d3c51
--- /dev/null
+++ b/tests/test_builders.py
@@ -0,0 +1,87 @@
+import os
+
+import pytest
+import sphinx
+from sphinx import addnodes
+try:
+ # Available from Sphinx 2.0
+ from sphinx.builders.dirhtml import DirectoryHTMLBuilder
+ from sphinx.builders.singlehtml import SingleFileHTMLBuilder
+except ImportError:
+ from sphinx.builders.html import (
+ DirectoryHTMLBuilder,
+ SingleFileHTMLBuilder,
+ )
+
+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 = (
+ '<ul>\n'
+ '<li class="toctree-l1">'
+ '<a class="reference internal" href="index.html#document-foo">foo</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()
+ 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
diff --git a/tests/util.py b/tests/util.py
new file mode 100644
index 0000000..c9fdcc1
--- /dev/null
+++ b/tests/util.py
@@ -0,0 +1,61 @@
+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('sphinx_rtd_theme')
+ 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