refs #1777: add test for loading theme plugins

This commit is contained in:
shimizukawa 2015-03-15 00:47:43 +09:00
parent f32c5c475e
commit 1628eebfb5
7 changed files with 83 additions and 1 deletions

View File

@ -0,0 +1,2 @@
recursive-include test_theme *.conf

View File

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
html_theme = 'test-theme'
master = 'index'

View File

@ -0,0 +1,5 @@
=======
Theming
=======

View File

@ -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
""",
)

View File

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
import os
def get_path():
return os.path.dirname(os.path.abspath(__file__))

View File

@ -0,0 +1,2 @@
[theme]
inherit = classic

View File

@ -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()