diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:56:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:56:50 +0000 |
commit | 6637322c8ab1c5ff80a2b6ca59c9ba1d40aeba2c (patch) | |
tree | 04e41667e9eae835f5d88bda4f6d3f5c2664de01 /tests/util.py | |
parent | Initial commit. (diff) | |
download | sphinx-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/util.py')
-rw-r--r-- | tests/util.py | 61 |
1 files changed, 61 insertions, 0 deletions
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 |