1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.errors import ConfigError
if TYPE_CHECKING:
from sphinx.testing.util import SphinxTestApp
@pytest.mark.sphinx('html', testroot='basic')
def test_default_html_math_renderer(app: SphinxTestApp) -> None:
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking
assert app.builder.math_renderer_name == 'mathjax'
@pytest.mark.sphinx(
'html',
testroot='basic',
confoverrides={'extensions': ['sphinx.ext.mathjax']},
)
def test_html_math_renderer_is_mathjax(app: SphinxTestApp) -> None:
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking
assert app.builder.math_renderer_name == 'mathjax'
@pytest.mark.sphinx(
'html',
testroot='basic',
confoverrides={'extensions': ['sphinx.ext.imgmath']},
)
def test_html_math_renderer_is_imgmath(app: SphinxTestApp) -> None:
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking
assert app.builder.math_renderer_name == 'imgmath'
@pytest.mark.skip('Requires sphinxcontrib.jsmath module')
@pytest.mark.sphinx(
'html',
testroot='basic',
confoverrides={'extensions': ['sphinxcontrib.jsmath', 'sphinx.ext.imgmath']},
)
def test_html_math_renderer_is_duplicated(make_app, app_params):
args, kwargs = app_params
with pytest.raises(
ConfigError,
match=r'Many math_renderers are registered\. But no math_renderer is selected\.',
):
make_app(*args, **kwargs)
@pytest.mark.sphinx(
'html',
testroot='basic',
confoverrides={'extensions': ['sphinx.ext.imgmath', 'sphinx.ext.mathjax']},
)
def test_html_math_renderer_is_duplicated2(app: SphinxTestApp) -> None:
# case of both mathjax and another math_renderer is loaded
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking
assert app.builder.math_renderer_name == 'imgmath' # The another one is chosen
@pytest.mark.skip('Requires sphinxcontrib.jsmath module')
@pytest.mark.sphinx(
'html',
testroot='basic',
confoverrides={
'extensions': ['sphinxcontrib.jsmath', 'sphinx.ext.imgmath'],
'html_math_renderer': 'imgmath',
},
)
def test_html_math_renderer_is_chosen(app: SphinxTestApp) -> None:
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking
assert app.builder.math_renderer_name == 'imgmath'
@pytest.mark.skip('Requires sphinxcontrib.jsmath module')
@pytest.mark.sphinx(
'html',
testroot='basic',
confoverrides={
'extensions': ['sphinxcontrib.jsmath', 'sphinx.ext.mathjax'],
'html_math_renderer': 'imgmath',
},
)
def test_html_math_renderer_is_mismatched(make_app, app_params):
args, kwargs = app_params
with pytest.raises(
ConfigError,
match=r"Unknown math_renderer 'imgmath' is given\.",
):
make_app(*args, **kwargs)
|