summaryrefslogtreecommitdiffstats
path: root/tests/test_writers/test_api_translator.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_writers/test_api_translator.py')
-rw-r--r--tests/test_writers/test_api_translator.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/test_writers/test_api_translator.py b/tests/test_writers/test_api_translator.py
new file mode 100644
index 0000000..9f2bd44
--- /dev/null
+++ b/tests/test_writers/test_api_translator.py
@@ -0,0 +1,92 @@
+"""Test the Sphinx API for translator."""
+
+import sys
+
+import pytest
+
+
+@pytest.fixture(scope='module', autouse=True)
+def _setup_module(rootdir):
+ p = rootdir / 'test-api-set-translator'
+ sys.path.insert(0, p)
+ yield
+ sys.path.remove(p)
+
+
+@pytest.mark.sphinx('html')
+def test_html_translator(app, status, warning):
+ # no set_translator()
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'HTML5Translator'
+
+
+@pytest.mark.sphinx('html', testroot='api-set-translator')
+def test_html_with_set_translator_for_html_(app, status, warning):
+ # use set_translator()
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfHTMLTranslator'
+
+
+@pytest.mark.sphinx('singlehtml', testroot='api-set-translator')
+def test_singlehtml_set_translator_for_singlehtml(app, status, warning):
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfSingleHTMLTranslator'
+
+
+@pytest.mark.sphinx('pickle', testroot='api-set-translator')
+def test_pickle_set_translator_for_pickle(app, status, warning):
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfPickleTranslator'
+
+
+@pytest.mark.sphinx('json', testroot='api-set-translator')
+def test_json_set_translator_for_json(app, status, warning):
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfJsonTranslator'
+
+
+@pytest.mark.sphinx('latex', testroot='api-set-translator')
+def test_html_with_set_translator_for_latex(app, status, warning):
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfLaTeXTranslator'
+
+
+@pytest.mark.sphinx('man', testroot='api-set-translator')
+def test_html_with_set_translator_for_man(app, status, warning):
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfManualPageTranslator'
+
+
+@pytest.mark.sphinx('texinfo', testroot='api-set-translator')
+def test_html_with_set_translator_for_texinfo(app, status, warning):
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfTexinfoTranslator'
+
+
+@pytest.mark.sphinx('text', testroot='api-set-translator')
+def test_html_with_set_translator_for_text(app, status, warning):
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfTextTranslator'
+
+
+@pytest.mark.sphinx('xml', testroot='api-set-translator')
+def test_html_with_set_translator_for_xml(app, status, warning):
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfXMLTranslator'
+
+
+@pytest.mark.sphinx('pseudoxml', testroot='api-set-translator')
+def test_html_with_set_translator_for_pseudoxml(app, status, warning):
+ translator_class = app.builder.get_translator_class()
+ assert translator_class
+ assert translator_class.__name__ == 'ConfPseudoXMLTranslator'