summaryrefslogtreecommitdiffstats
path: root/tests/test_writers/test_writer_latex.py
blob: a0ab3ee59159139084ecfafb6f6910f3b7cde6c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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'