| 1 |
"""Test templating.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from typing import TYPE_CHECKING |
| 6 |
|
| 7 |
import pytest |
| 8 |
|
| 9 |
if TYPE_CHECKING: |
| 10 |
from collections.abc import Callable |
| 11 |
|
| 12 |
from sphinx.testing.fixtures import _app_params |
| 13 |
from sphinx.testing.util import SphinxTestApp |
| 14 |
|
| 15 |
|
| 16 |
@pytest.mark.sphinx('html', testroot='templating', copy_test_root=True) |
| 17 |
def test_layout_overloading( |
| 18 |
make_app: Callable[..., SphinxTestApp], app_params: _app_params |
| 19 |
) -> None: |
| 20 |
args, kwargs = app_params |
| 21 |
app = make_app(*args, **kwargs) |
| 22 |
app.build() |
| 23 |
|
| 24 |
result = (app.outdir / 'index.html').read_text(encoding='utf8') |
| 25 |
assert '<!-- layout overloading -->' in result |
| 26 |
|
| 27 |
|
| 28 |
@pytest.mark.sphinx('html', testroot='templating', copy_test_root=True) |
| 29 |
def test_autosummary_class_template_overloading( |
| 30 |
make_app: Callable[..., SphinxTestApp], app_params: _app_params |
| 31 |
) -> None: |
| 32 |
args, kwargs = app_params |
| 33 |
app = make_app(*args, **kwargs) |
| 34 |
app.build() |
| 35 |
|
| 36 |
result = ( |
| 37 |
app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html' |
| 38 |
).read_text(encoding='utf8') |
| 39 |
assert 'autosummary/class.rst method block overloading' in result |
| 40 |
assert 'foobar' not in result |
| 41 |
|
| 42 |
|
| 43 |
@pytest.mark.sphinx( |
| 44 |
'html', |
| 45 |
testroot='templating', |
| 46 |
confoverrides={'autosummary_context': {'sentence': 'foobar'}}, |
| 47 |
copy_test_root=True, |
| 48 |
) |
| 49 |
def test_autosummary_context( |
| 50 |
make_app: Callable[..., SphinxTestApp], app_params: _app_params |
| 51 |
) -> None: |
| 52 |
args, kwargs = app_params |
| 53 |
app = make_app(*args, **kwargs) |
| 54 |
app.build() |
| 55 |
|
| 56 |
result = ( |
| 57 |
app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html' |
| 58 |
).read_text(encoding='utf8') |
| 59 |
assert 'autosummary/class.rst method block overloading' in result |
| 60 |
assert 'foobar' in result |