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