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