2009-02-15 09:10:10 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_theming
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the Theme class.
|
|
|
|
|
2017-03-22 06:21:12 -05:00
|
|
|
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
|
2009-02-15 09:10:10 -06:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2017-01-05 09:46:42 -06:00
|
|
|
import pytest
|
2016-10-15 02:22:27 -05:00
|
|
|
|
2017-04-20 06:19:55 -05:00
|
|
|
from sphinx.theming import ThemeError
|
2015-03-14 10:47:43 -05:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(
|
|
|
|
confoverrides={'html_theme': 'ziptheme',
|
|
|
|
'html_theme_options.testopt': 'foo'})
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_theme_api(app, status, warning):
|
2009-02-15 09:10:10 -06:00
|
|
|
cfg = app.config
|
|
|
|
|
|
|
|
# test Theme class API
|
2017-04-20 06:19:55 -05:00
|
|
|
assert set(app.html_themes.keys()) == \
|
2014-09-21 10:17:02 -05:00
|
|
|
set(['basic', 'default', 'scrolls', 'agogo', 'sphinxdoc', 'haiku',
|
|
|
|
'traditional', 'testtheme', 'ziptheme', 'epub', 'nature',
|
2016-07-13 02:27:11 -05:00
|
|
|
'pyramid', 'bizstyle', 'classic', 'nonav'])
|
2017-04-20 06:19:55 -05:00
|
|
|
assert app.html_themes['testtheme'] == app.srcdir / 'testtheme'
|
|
|
|
assert app.html_themes['ziptheme'] == app.srcdir / 'ziptheme.zip'
|
2009-02-15 09:10:10 -06:00
|
|
|
|
|
|
|
# test Theme instance API
|
|
|
|
theme = app.builder.theme
|
|
|
|
assert theme.name == 'ziptheme'
|
|
|
|
themedir = theme.themedir
|
|
|
|
assert theme.base.name == 'basic'
|
2017-04-20 09:38:48 -05:00
|
|
|
assert len(theme.get_theme_dirs()) == 2
|
2009-02-15 09:10:10 -06:00
|
|
|
|
|
|
|
# direct setting
|
2017-04-20 09:38:48 -05:00
|
|
|
assert theme.get_config('theme', 'stylesheet') == 'custom.css'
|
2009-02-15 09:10:10 -06:00
|
|
|
# inherited setting
|
2017-04-20 09:38:48 -05:00
|
|
|
assert theme.get_config('options', 'nosidebar') == 'false'
|
2009-02-15 09:10:10 -06:00
|
|
|
# nonexisting setting
|
2017-04-20 09:38:48 -05:00
|
|
|
assert theme.get_config('theme', 'foobar', 'def') == 'def'
|
2017-01-05 09:46:42 -06:00
|
|
|
with pytest.raises(ThemeError):
|
2017-04-20 09:38:48 -05:00
|
|
|
theme.get_config('theme', 'foobar')
|
2009-02-15 09:10:10 -06:00
|
|
|
|
|
|
|
# options API
|
2017-01-05 09:46:42 -06:00
|
|
|
with pytest.raises(ThemeError):
|
|
|
|
theme.get_options({'nonexisting': 'foo'})
|
2009-02-15 09:10:10 -06:00
|
|
|
options = theme.get_options(cfg.html_theme_options)
|
|
|
|
assert options['testopt'] == 'foo'
|
|
|
|
assert options['nosidebar'] == 'false'
|
|
|
|
|
|
|
|
# cleanup temp directories
|
|
|
|
theme.cleanup()
|
|
|
|
assert not os.path.exists(themedir)
|
2014-06-07 04:32:56 -05:00
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(testroot='tocdepth') # a minimal root
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_js_source(app, status, warning):
|
2014-06-07 04:32:56 -05:00
|
|
|
# Now sphinx provides non-minified JS files for jquery.js and underscore.js
|
|
|
|
# to clarify the source of the minified files. see also #1434.
|
|
|
|
# If you update the version of the JS file, please update the source of the
|
|
|
|
# JS file and version number in this test.
|
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
app.builder.build(['contents'])
|
2014-06-07 04:32:56 -05:00
|
|
|
|
2016-07-13 00:01:55 -05:00
|
|
|
v = '3.1.0'
|
2014-06-07 04:32:56 -05:00
|
|
|
msg = 'jquery.js version does not match to {v}'.format(v=v)
|
|
|
|
jquery_min = (app.outdir / '_static' / 'jquery.js').text()
|
|
|
|
assert 'jQuery v{v}'.format(v=v) in jquery_min, msg
|
|
|
|
jquery_src = (app.outdir / '_static' / 'jquery-{v}.js'.format(v=v)).text()
|
|
|
|
assert 'jQuery JavaScript Library v{v}'.format(v=v) in jquery_src, msg
|
|
|
|
|
|
|
|
v = '1.3.1'
|
|
|
|
msg = 'underscore.js version does not match to {v}'.format(v=v)
|
|
|
|
underscore_min = (app.outdir / '_static' / 'underscore.js').text()
|
|
|
|
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
|
2015-11-21 09:13:42 -06:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(testroot='double-inheriting-theme')
|
2017-04-20 00:04:49 -05:00
|
|
|
def test_double_inheriting_theme(app, status, warning):
|
|
|
|
assert app.builder.theme.name == 'base_theme2'
|
|
|
|
app.build() # => not raises TemplateNotFound
|
2017-04-18 09:22:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx(testroot='theming',
|
|
|
|
confoverrides={'html_theme': 'child'})
|
|
|
|
def test_nested_zipped_theme(app, status, warning):
|
2017-04-20 00:04:49 -05:00
|
|
|
assert app.builder.theme.name == 'child'
|
2017-04-18 09:22:03 -05:00
|
|
|
app.build() # => not raises TemplateNotFound
|