Debian Codegraph @

test/test_writers/test_xetex_misc.py

raw symbols SCIP
1 #! /usr/bin/env python3
2 # $Id: test_xetex_misc.py 9997 2024-12-11 14:36:22Z milde $
3 # Author: Günter Milde
4 # Maintainer: [email protected]
5 # :Copyright: 2024 Günter Milde,
6 # :License: Released under the terms of the `2-Clause BSD license`_, in short:
7 #
8 # Copying and distribution of this file, with or without modification,
9 # are permitted in any medium without royalty provided the copyright
10 # notice and this notice are preserved.
11 # This file is offered as-is, without any warranty.
12 #
13 # .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
14
15 """
16 Miscellaneous XeTeX/LuaTeX writer tests.
17 """
18
19 from pathlib import Path
20 import sys
21 import unittest
22
23
24 if __name__ == '__main__':
25 # prepend the "docutils root" to the Python library path
26 # so we import the local `docutils` package.
27 sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
28
29 from docutils import core
30 from docutils.writers import xetex
31
32 # TEST_ROOT is ./test/ from the docutils root
33 TEST_ROOT = Path(__file__).parents[1]
34 DATA_ROOT = TEST_ROOT / 'data'
35
36 px_sample = """\
37 .. image:: foo.pdf
38 :width: 250 px
39 :height: 50pt
40 """
41
42 px_body = r"""
43 \includegraphics[height=50bp,width=250\pdfpxdimen]{foo.pdf}
44 """
45
46 px_fallback = r"""
47 % Provide a length variable and set default, if it is new
48 \providecommand*{\DUprovidelength}[2]{%
49 \ifdefined#1
50 \else
51 \newlength{#1}\setlength{#1}{#2}%
52 \fi
53 }
54
55 \DUprovidelength{\pdfpxdimen}{1bp}
56 """
57
58
59 class PublishTestCase(unittest.TestCase):
60 maxDiff = None
61
62 settings = {'_disable_config': True,
63 # avoid latex writer future warnings:
64 'use_latex_citations': False,
65 'legacy_column_widths': False,
66 }
67
68 def test_px_workaround(self):
69 """Check the workaround for length unit 'px' missing in XeTeX.
70 """
71 parts = core.publish_parts(px_sample,
72 writer=xetex.Writer(),
73 settings_overrides=self.settings)
74 self.assertEqual(px_body, parts['body'])
75 self.assertEqual(px_fallback, parts['fallbacks'])
76
77
78 if __name__ == '__main__':
79 unittest.main()