| 1 |
"""Test the Sphinx API for translator.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
import sys |
| 6 |
from typing import TYPE_CHECKING |
| 7 |
|
| 8 |
import pytest |
| 9 |
|
| 10 |
from sphinx.testing.util import SphinxTestApp |
| 11 |
|
| 12 |
if TYPE_CHECKING: |
| 13 |
from collections.abc import Iterator |
| 14 |
from pathlib import Path |
| 15 |
|
| 16 |
from sphinx.testing.util import SphinxTestApp |
| 17 |
|
| 18 |
|
| 19 |
@pytest.fixture(scope='module', autouse=True) |
| 20 |
def _setup_module(rootdir: Path) -> Iterator[None]: |
| 21 |
saved_path = sys.path.copy() |
| 22 |
sys.path.insert(0, str(rootdir / 'test-api-set-translator')) |
| 23 |
yield |
| 24 |
sys.path[:] = saved_path |
| 25 |
|
| 26 |
|
| 27 |
@pytest.mark.sphinx('html', testroot='root') |
| 28 |
def test_html_translator(app: SphinxTestApp) -> None: |
| 29 |
# no set_translator() |
| 30 |
translator_class = app.builder.get_translator_class() |
| 31 |
assert translator_class |
| 32 |
assert translator_class.__name__ == 'HTML5Translator' |
| 33 |
|
| 34 |
|
| 35 |
@pytest.mark.sphinx('html', testroot='api-set-translator') |
| 36 |
def test_html_with_set_translator_for_html_(app: SphinxTestApp) -> None: |
| 37 |
# use set_translator() |
| 38 |
translator_class = app.builder.get_translator_class() |
| 39 |
assert translator_class |
| 40 |
assert translator_class.__name__ == 'ConfHTMLTranslator' |
| 41 |
|
| 42 |
|
| 43 |
@pytest.mark.sphinx('singlehtml', testroot='api-set-translator') |
| 44 |
def test_singlehtml_set_translator_for_singlehtml(app: SphinxTestApp) -> None: |
| 45 |
translator_class = app.builder.get_translator_class() |
| 46 |
assert translator_class |
| 47 |
assert translator_class.__name__ == 'ConfSingleHTMLTranslator' |
| 48 |
|
| 49 |
|
| 50 |
@pytest.mark.sphinx('pickle', testroot='api-set-translator') |
| 51 |
def test_pickle_set_translator_for_pickle(app: SphinxTestApp) -> None: |
| 52 |
translator_class = app.builder.get_translator_class() |
| 53 |
assert translator_class |
| 54 |
assert translator_class.__name__ == 'ConfPickleTranslator' |
| 55 |
|
| 56 |
|
| 57 |
@pytest.mark.sphinx('json', testroot='api-set-translator') |
| 58 |
def test_json_set_translator_for_json(app: SphinxTestApp) -> None: |
| 59 |
translator_class = app.builder.get_translator_class() |
| 60 |
assert translator_class |
| 61 |
assert translator_class.__name__ == 'ConfJsonTranslator' |
| 62 |
|
| 63 |
|
| 64 |
@pytest.mark.sphinx('latex', testroot='api-set-translator') |
| 65 |
def test_html_with_set_translator_for_latex(app: SphinxTestApp) -> None: |
| 66 |
translator_class = app.builder.get_translator_class() |
| 67 |
assert translator_class |
| 68 |
assert translator_class.__name__ == 'ConfLaTeXTranslator' |
| 69 |
|
| 70 |
|
| 71 |
@pytest.mark.sphinx('man', testroot='api-set-translator') |
| 72 |
def test_html_with_set_translator_for_man(app: SphinxTestApp) -> None: |
| 73 |
translator_class = app.builder.get_translator_class() |
| 74 |
assert translator_class |
| 75 |
assert translator_class.__name__ == 'ConfManualPageTranslator' |
| 76 |
|
| 77 |
|
| 78 |
@pytest.mark.sphinx('texinfo', testroot='api-set-translator') |
| 79 |
def test_html_with_set_translator_for_texinfo(app: SphinxTestApp) -> None: |
| 80 |
translator_class = app.builder.get_translator_class() |
| 81 |
assert translator_class |
| 82 |
assert translator_class.__name__ == 'ConfTexinfoTranslator' |
| 83 |
|
| 84 |
|
| 85 |
@pytest.mark.sphinx('text', testroot='api-set-translator') |
| 86 |
def test_html_with_set_translator_for_text(app: SphinxTestApp) -> None: |
| 87 |
translator_class = app.builder.get_translator_class() |
| 88 |
assert translator_class |
| 89 |
assert translator_class.__name__ == 'ConfTextTranslator' |
| 90 |
|
| 91 |
|
| 92 |
@pytest.mark.sphinx('xml', testroot='api-set-translator') |
| 93 |
def test_html_with_set_translator_for_xml(app: SphinxTestApp) -> None: |
| 94 |
translator_class = app.builder.get_translator_class() |
| 95 |
assert translator_class |
| 96 |
assert translator_class.__name__ == 'ConfXMLTranslator' |
| 97 |
|
| 98 |
|
| 99 |
@pytest.mark.sphinx('pseudoxml', testroot='api-set-translator') |
| 100 |
def test_html_with_set_translator_for_pseudoxml(app: SphinxTestApp) -> None: |
| 101 |
translator_class = app.builder.get_translator_class() |
| 102 |
assert translator_class |
| 103 |
assert translator_class.__name__ == 'ConfPseudoXMLTranslator' |