| 1 |
"""Test the LaTeX writer""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
from sphinx.writers.latex import rstdim_to_latexdim |
| 8 |
|
| 9 |
|
| 10 |
def test_rstdim_to_latexdim() -> None: |
| 11 |
# Length units docutils supported |
| 12 |
# https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#length-units |
| 13 |
assert rstdim_to_latexdim('160em') == '160em' |
| 14 |
assert rstdim_to_latexdim('160px') == '160\\sphinxpxdimen' |
| 15 |
assert rstdim_to_latexdim('160in') == '160in' |
| 16 |
assert rstdim_to_latexdim('160cm') == '160cm' |
| 17 |
assert rstdim_to_latexdim('160mm') == '160mm' |
| 18 |
assert rstdim_to_latexdim('160pt') == '160bp' |
| 19 |
assert rstdim_to_latexdim('160pc') == '160pc' |
| 20 |
assert rstdim_to_latexdim('30%') == '0.300\\linewidth' |
| 21 |
assert rstdim_to_latexdim('160') == '160\\sphinxpxdimen' |
| 22 |
|
| 23 |
# float values |
| 24 |
assert rstdim_to_latexdim('160.0em') == '160.0em' |
| 25 |
assert rstdim_to_latexdim('.5em') == '.5em' |
| 26 |
|
| 27 |
# unknown values (it might be generated by 3rd party extension) |
| 28 |
with pytest.raises(ValueError, match='could not convert string to float: '): |
| 29 |
rstdim_to_latexdim('unknown') |
| 30 |
assert rstdim_to_latexdim('160.0unknown') == '160.0unknown' |