diff --git a/tests/roots/test-theming/MANIFEST.in b/tests/roots/test-theming/MANIFEST.in new file mode 100644 index 000000000..0e977e756 --- /dev/null +++ b/tests/roots/test-theming/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include test_theme *.conf + diff --git a/tests/roots/test-theming/conf.py b/tests/roots/test-theming/conf.py new file mode 100644 index 000000000..6eecc8343 --- /dev/null +++ b/tests/roots/test-theming/conf.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +html_theme = 'test-theme' +master = 'index' + diff --git a/tests/roots/test-theming/index.rst b/tests/roots/test-theming/index.rst new file mode 100644 index 000000000..18a9a4e2f --- /dev/null +++ b/tests/roots/test-theming/index.rst @@ -0,0 +1,5 @@ +======= +Theming +======= + + diff --git a/tests/roots/test-theming/setup.py b/tests/roots/test-theming/setup.py new file mode 100644 index 000000000..34299647d --- /dev/null +++ b/tests/roots/test-theming/setup.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +# -*- coding: utf-8 -*- +from setuptools import setup, find_packages + +setup( + name='test-theme', + packages=find_packages(), + include_package_data=True, + entry_points=""" + [sphinx_themes] + path = test_theme:get_path + """, +) + + diff --git a/tests/roots/test-theming/test_theme/__init__.py b/tests/roots/test-theming/test_theme/__init__.py new file mode 100644 index 000000000..2d63e888f --- /dev/null +++ b/tests/roots/test-theming/test_theme/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +import os + +def get_path(): + return os.path.dirname(os.path.abspath(__file__)) diff --git a/tests/roots/test-theming/test_theme/test-theme/theme.conf b/tests/roots/test-theming/test_theme/test-theme/theme.conf new file mode 100644 index 000000000..0d8403f0b --- /dev/null +++ b/tests/roots/test-theming/test_theme/test-theme/theme.conf @@ -0,0 +1,2 @@ +[theme] +inherit = classic diff --git a/tests/test_theming.py b/tests/test_theming.py index 77a8b5d8f..4e5476cb4 100644 --- a/tests/test_theming.py +++ b/tests/test_theming.py @@ -11,10 +11,44 @@ import os import zipfile +import sys +import subprocess +from functools import wraps +import tempfile +from path import path from sphinx.theming import Theme, ThemeError +from sphinx.util.osutil import cd -from util import with_app, raises +from util import with_app, raises, TestApp, rootdir + + +def with_theme_setup(root, *args, **kwds): + """ + Run `setup.py build_sphinx` with args and kwargs, + pass it to the test and clean up properly. + """ + def generator(func): + @wraps(func) + def deco(*args2, **kwargs2): + tempdir = path(tempfile.mkdtemp()) + testrootdir = rootdir / 'roots' / ('test-' + root) + pkgdir = tempdir / root + testrootdir.copytree(pkgdir) + with cd(pkgdir): + command = [sys.executable, 'setup.py', 'install'] + command.extend(args) + try: + proc = subprocess.Popen( + command, + env=os.environ, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + func(pkgdir, proc) + finally: + tempdir.rmtree(ignore_errors=True) + return deco + return generator @with_app(confoverrides={'html_theme': 'ziptheme', @@ -79,3 +113,16 @@ def test_js_source(app, status, warning): assert 'Underscore.js {v}'.format(v=v) in underscore_min, msg underscore_src = (app.outdir / '_static' / 'underscore-{v}.js'.format(v=v)).text() assert 'Underscore.js {v}'.format(v=v) in underscore_src, msg + + +@with_theme_setup('theming') +def test_theme_plugin(pkgroot, proc): + out, err = proc.communicate() + print(out) + print(err) + assert proc.returncode == 0, 'expect zero status for setup.py' + app = TestApp(testroot='theming') + try: + assert 'test-theme' in Theme.themes + finally: + app.cleanup()