2014-08-04 10:18:54 -05:00
|
|
|
"""Test the Sphinx API for translator."""
|
2014-08-04 11:54:56 -05:00
|
|
|
|
2024-11-22 15:54:26 -06:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
import sys
|
2014-08-04 10:18:54 -05:00
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
import pytest
|
2014-08-04 10:18:54 -05:00
|
|
|
|
|
|
|
|
2017-05-07 02:46:44 -05:00
|
|
|
@pytest.fixture(scope='module', autouse=True)
|
2023-02-17 17:46:31 -06:00
|
|
|
def _setup_module(rootdir):
|
2024-07-23 10:55:21 -05:00
|
|
|
saved_path = sys.path.copy()
|
|
|
|
sys.path.insert(0, str(rootdir / 'test-api-set-translator'))
|
2017-05-07 02:46:44 -05:00
|
|
|
yield
|
2024-07-23 10:55:21 -05:00
|
|
|
sys.path[:] = saved_path
|
2014-08-04 11:54:56 -05:00
|
|
|
|
|
|
|
|
2024-08-12 16:34:03 -05:00
|
|
|
@pytest.mark.sphinx('html', testroot='root')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_html_translator(app):
|
2017-01-01 07:58:14 -06:00
|
|
|
# no set_translator()
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
2022-04-16 22:36:20 -05:00
|
|
|
assert translator_class.__name__ == 'HTML5Translator'
|
2014-08-04 10:18:54 -05:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_html_with_set_translator_for_html_(app):
|
2017-01-01 07:58:14 -06:00
|
|
|
# use set_translator()
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfHTMLTranslator'
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('singlehtml', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_singlehtml_set_translator_for_singlehtml(app):
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfSingleHTMLTranslator'
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('pickle', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_pickle_set_translator_for_pickle(app):
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfPickleTranslator'
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('json', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_json_set_translator_for_json(app):
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfJsonTranslator'
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('latex', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_html_with_set_translator_for_latex(app):
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfLaTeXTranslator'
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('man', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_html_with_set_translator_for_man(app):
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfManualPageTranslator'
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('texinfo', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_html_with_set_translator_for_texinfo(app):
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfTexinfoTranslator'
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('text', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_html_with_set_translator_for_text(app):
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfTextTranslator'
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('xml', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_html_with_set_translator_for_xml(app):
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfXMLTranslator'
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('pseudoxml', testroot='api-set-translator')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_html_with_set_translator_for_pseudoxml(app):
|
2017-03-11 22:42:12 -06:00
|
|
|
translator_class = app.builder.get_translator_class()
|
2014-08-04 10:18:54 -05:00
|
|
|
assert translator_class
|
|
|
|
assert translator_class.__name__ == 'ConfPseudoXMLTranslator'
|