| 1 |
|
| 2 |
|
| 3 |
e |
| 4 |
|
| 5 |
, |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
""" |
| 16 |
Miscellaneous LaTeX writer tests. |
| 17 |
""" |
| 18 |
|
| 19 |
from pathlib import Path |
| 20 |
import sys |
| 21 |
import unittest |
| 22 |
|
| 23 |
|
| 24 |
if __name__ == '__main__': |
| 25 |
|
| 26 |
|
| 27 |
sys.path.insert(0, str(Path(__file__).resolve().parents[2])) |
| 28 |
|
| 29 |
from docutils import core |
| 30 |
from docutils.writers import latex2e |
| 31 |
|
| 32 |
|
| 33 |
TEST_ROOT = Path(__file__).parents[1] |
| 34 |
DATA_ROOT = TEST_ROOT / 'data' |
| 35 |
|
| 36 |
sample_toc = """\ |
| 37 |
.. contents:: TOC |
| 38 |
|
| 39 |
foo |
| 40 |
--- |
| 41 |
|
| 42 |
bar |
| 43 |
--- |
| 44 |
|
| 45 |
""" |
| 46 |
|
| 47 |
sample_multiterm = f"""\ |
| 48 |
.. include:: {DATA_ROOT}/multiple-term-definition.xml |
| 49 |
:parser: xml |
| 50 |
""" |
| 51 |
expected_multiterm = """ |
| 52 |
\\begin{description} |
| 53 |
\\item[{New in Docutils 0.22}] \n\ |
| 54 |
A definition list item may contain several |
| 55 |
terms with optional classifier(s). |
| 56 |
|
| 57 |
However, there is currently no corresponding |
| 58 |
reStructuredText syntax. |
| 59 |
|
| 60 |
\\item[{term 2a}] \n\ |
| 61 |
\\item[{term 2b}] \n\ |
| 62 |
definition 2 |
| 63 |
|
| 64 |
\\item[{term 3a}] (\\textbf{classifier 3a}) |
| 65 |
(\\textbf{classifier 3aa}) |
| 66 |
\\item[{term 3b}] (\\textbf{classifier 3b}) |
| 67 |
definition 3 |
| 68 |
\\end{description} |
| 69 |
""" |
| 70 |
|
| 71 |
|
| 72 |
class PublishTestCase(unittest.TestCase): |
| 73 |
maxDiff = None |
| 74 |
|
| 75 |
settings = {'_disable_config': True, |
| 76 |
|
| 77 |
'use_latex_citations': False, |
| 78 |
'legacy_column_widths': False, |
| 79 |
} |
| 80 |
|
| 81 |
def test_publish_from_doctree(self): |
| 82 |
"""Ignore the Docutils-generated ToC when ``use_latex_toc`` is True. |
| 83 |
|
| 84 |
(This did happen when publishing from a doctree.) |
| 85 |
""" |
| 86 |
settings = self.settings.copy() |
| 87 |
settings['output_encoding'] = 'unicode' |
| 88 |
settings['warning_stream'] = '' |
| 89 |
doctree = core.publish_doctree(sample_toc, |
| 90 |
settings_overrides=settings) |
| 91 |
result = core.publish_from_doctree(doctree, |
| 92 |
writer=latex2e.Writer(), |
| 93 |
settings_overrides=settings) |
| 94 |
self.assertNotIn(r'\item \hyperref[foo]{foo}', result) |
| 95 |
self.assertIn(r'\tableofcontents', result) |
| 96 |
|
| 97 |
|
| 98 |
class WarningsTestCase(unittest.TestCase): |
| 99 |
|
| 100 |
def test_future_warnings(self): |
| 101 |
"""Warn about changing defaults.""" |
| 102 |
|
| 103 |
settings = {'_disable_config': True, |
| 104 |
|
| 105 |
|
| 106 |
'output_encoding': 'unicode', |
| 107 |
} |
| 108 |
with self.assertWarnsRegex(FutureWarning, |
| 109 |
'"legacy_column_widths" will change'): |
| 110 |
core.publish_string('warnings test', writer=latex2e.Writer(), |
| 111 |
settings_overrides=settings) |
| 112 |
with self.assertWarnsRegex(FutureWarning, |
| 113 |
'"use_latex_citations" will change'): |
| 114 |
core.publish_string('warnings test', writer=latex2e.Writer(), |
| 115 |
settings_overrides=settings) |
| 116 |
|
| 117 |
def test_deprecation_warnings(self): |
| 118 |
with self.assertWarnsRegex(DeprecationWarning, 'will be removed'): |
| 119 |
latex2e.SortableDict(deprecated=True) |
| 120 |
|
| 121 |
|
| 122 |
if __name__ == '__main__': |
| 123 |
unittest.main() |