summaryrefslogtreecommitdiffstats
path: root/tests/test_writers
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_writers')
-rw-r--r--tests/test_writers/__init__.py0
-rw-r--r--tests/test_writers/test_api_translator.py92
-rw-r--r--tests/test_writers/test_docutilsconf.py29
-rw-r--r--tests/test_writers/test_writer_latex.py28
4 files changed, 149 insertions, 0 deletions
diff --git a/tests/test_writers/__init__.py b/tests/test_writers/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/test_writers/__init__.py
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'
diff --git a/tests/test_writers/test_docutilsconf.py b/tests/test_writers/test_docutilsconf.py
new file mode 100644
index 0000000..6422c30
--- /dev/null
+++ b/tests/test_writers/test_docutilsconf.py
@@ -0,0 +1,29 @@
+"""Test docutils.conf support for several writers."""
+
+import pytest
+from docutils import nodes
+
+from sphinx.testing.util import assert_node
+from sphinx.util.docutils import patch_docutils
+
+
+@pytest.mark.sphinx('dummy', testroot='docutilsconf', freshenv=True)
+def test_html_with_default_docutilsconf(app, status, warning):
+ with patch_docutils(app.confdir):
+ app.build()
+
+ doctree = app.env.get_doctree('index')
+ assert_node(doctree[0][1], [nodes.paragraph, ("Sphinx ",
+ [nodes.footnote_reference, "1"])])
+
+
+@pytest.mark.sphinx('dummy', testroot='docutilsconf', freshenv=True,
+ docutils_conf=('[restructuredtext parser]\n'
+ 'trim_footnote_reference_space: true\n'))
+def test_html_with_docutilsconf(app, status, warning):
+ with patch_docutils(app.confdir):
+ app.build()
+
+ doctree = app.env.get_doctree('index')
+ assert_node(doctree[0][1], [nodes.paragraph, ("Sphinx",
+ [nodes.footnote_reference, "1"])])
diff --git a/tests/test_writers/test_writer_latex.py b/tests/test_writers/test_writer_latex.py
new file mode 100644
index 0000000..a0ab3ee
--- /dev/null
+++ b/tests/test_writers/test_writer_latex.py
@@ -0,0 +1,28 @@
+"""Test the LaTeX writer"""
+
+import pytest
+
+from sphinx.writers.latex import rstdim_to_latexdim
+
+
+def test_rstdim_to_latexdim():
+ # Length units docutils supported
+ # https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#length-units
+ assert rstdim_to_latexdim('160em') == '160em'
+ assert rstdim_to_latexdim('160px') == '160\\sphinxpxdimen'
+ assert rstdim_to_latexdim('160in') == '160in'
+ assert rstdim_to_latexdim('160cm') == '160cm'
+ assert rstdim_to_latexdim('160mm') == '160mm'
+ assert rstdim_to_latexdim('160pt') == '160bp'
+ assert rstdim_to_latexdim('160pc') == '160pc'
+ assert rstdim_to_latexdim('30%') == '0.300\\linewidth'
+ assert rstdim_to_latexdim('160') == '160\\sphinxpxdimen'
+
+ # float values
+ assert rstdim_to_latexdim('160.0em') == '160.0em'
+ assert rstdim_to_latexdim('.5em') == '.5em'
+
+ # unknown values (it might be generated by 3rd party extension)
+ with pytest.raises(ValueError, match='could not convert string to float: '):
+ rstdim_to_latexdim('unknown')
+ assert rstdim_to_latexdim('160.0unknown') == '160.0unknown'