2016-06-26 13:15:07 +09:00
|
|
|
"""Test the LaTeX writer"""
|
|
|
|
|
|
2017-01-06 00:46:42 +09:00
|
|
|
import pytest
|
2016-06-26 13:31:07 +09:00
|
|
|
|
2018-02-19 22:39:14 +09:00
|
|
|
from sphinx.writers.latex import rstdim_to_latexdim
|
|
|
|
|
|
2016-06-26 13:15:07 +09:00
|
|
|
|
|
|
|
|
def test_rstdim_to_latexdim():
|
|
|
|
|
# Length units docutils supported
|
2021-05-16 15:42:26 +03:00
|
|
|
# https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#length-units
|
2016-06-26 13:15:07 +09:00
|
|
|
assert rstdim_to_latexdim('160em') == '160em'
|
2016-06-26 13:44:48 +09:00
|
|
|
assert rstdim_to_latexdim('160px') == '160\\sphinxpxdimen'
|
2016-06-26 13:15:07 +09:00
|
|
|
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'
|
2016-06-26 13:56:19 +09:00
|
|
|
assert rstdim_to_latexdim('160') == '160\\sphinxpxdimen'
|
2016-06-26 13:15:07 +09:00
|
|
|
|
2017-10-14 13:56:07 -07:00
|
|
|
# float values
|
2016-06-26 13:15:07 +09:00
|
|
|
assert rstdim_to_latexdim('160.0em') == '160.0em'
|
2016-06-26 13:44:48 +09:00
|
|
|
assert rstdim_to_latexdim('.5em') == '.5em'
|
2016-06-26 13:31:07 +09:00
|
|
|
|
|
|
|
|
# unknown values (it might be generated by 3rd party extension)
|
2023-08-10 12:46:03 +01:00
|
|
|
with pytest.raises(ValueError, match='could not convert string to float: '):
|
2017-01-06 00:46:42 +09:00
|
|
|
rstdim_to_latexdim('unknown')
|
2016-06-26 13:31:07 +09:00
|
|
|
assert rstdim_to_latexdim('160.0unknown') == '160.0unknown'
|