mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refs #1777: add test for loading theme plugins
This commit is contained in:
parent
f32c5c475e
commit
1628eebfb5
2
tests/roots/test-theming/MANIFEST.in
Normal file
2
tests/roots/test-theming/MANIFEST.in
Normal file
@ -0,0 +1,2 @@
|
||||
recursive-include test_theme *.conf
|
||||
|
5
tests/roots/test-theming/conf.py
Normal file
5
tests/roots/test-theming/conf.py
Normal file
@ -0,0 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
html_theme = 'test-theme'
|
||||
master = 'index'
|
||||
|
5
tests/roots/test-theming/index.rst
Normal file
5
tests/roots/test-theming/index.rst
Normal file
@ -0,0 +1,5 @@
|
||||
=======
|
||||
Theming
|
||||
=======
|
||||
|
||||
|
16
tests/roots/test-theming/setup.py
Normal file
16
tests/roots/test-theming/setup.py
Normal 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
|
||||
""",
|
||||
)
|
||||
|
||||
|
5
tests/roots/test-theming/test_theme/__init__.py
Normal file
5
tests/roots/test-theming/test_theme/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
|
||||
def get_path():
|
||||
return os.path.dirname(os.path.abspath(__file__))
|
@ -0,0 +1,2 @@
|
||||
[theme]
|
||||
inherit = classic
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user