sphinx/tests/test_theming/test_html_theme.py
Chris Sewell 66fa790b3a
[tests] Add basic build test for all builtin themes (#12168)
Add `tests/test_theming/test_theming.py::test_theme_builds`, which is a parametrized test against all builtin sphinx HTML themes, that tests:

1. that the themes builds without warnings for a basic project, and
2. that all `.html` files it produces are valid XML (see https://html.spec.whatwg.org/)

https://pypi.org/project/defusedxml/ was added to the test dependencies, in order to safely parse the XML

This required one fix for `sphinx/themes/basic/search.html`, and one for `sphinx/themes/bizstyle/layout.html`

Also, `tests/test_theming` was removed from the `ruff format` exclude list
2024-03-22 12:57:34 +01:00

36 lines
1.2 KiB
Python

import pytest
@pytest.mark.sphinx('html', testroot='theming')
def test_theme_options(app, status, warning):
app.build()
result = (app.outdir / '_static' / 'documentation_options.js').read_text(encoding='utf8')
assert 'NAVIGATION_WITH_KEYS: false' in result
assert 'ENABLE_SEARCH_SHORTCUTS: true' in result
@pytest.mark.sphinx(
'html',
testroot='theming',
confoverrides={
'html_theme_options.navigation_with_keys': True,
'html_theme_options.enable_search_shortcuts': False,
},
)
def test_theme_options_with_override(app, status, warning):
app.build()
result = (app.outdir / '_static' / 'documentation_options.js').read_text(encoding='utf8')
assert 'NAVIGATION_WITH_KEYS: true' in result
assert 'ENABLE_SEARCH_SHORTCUTS: false' in result
@pytest.mark.sphinx('html', testroot='build-html-theme-having-multiple-stylesheets')
def test_theme_having_multiple_stylesheets(app):
app.build()
content = (app.outdir / 'index.html').read_text(encoding='utf-8')
assert '<link rel="stylesheet" type="text/css" href="_static/mytheme.css" />' in content
assert '<link rel="stylesheet" type="text/css" href="_static/extra.css" />' in content