Test update.
[docutils.git] / docutils / test / test_writers / test_html_plain_misc.py
blobc31c098ed3b9cade5fddb6b8c73eda234b89bf0f
1 #! /usr/bin/env python
2 # coding: utf-8
4 # $Id$
5 # Authors: Lea Wiemann, Dmitry Shachnev, Günter Milde
6 # Maintainer: docutils-develop@lists.sourceforge.net
7 # Copyright: This module has been placed in the public domain.
9 """
10 Miscellaneous HTML writer tests.
11 """
13 from __init__ import DocutilsTestSupport
14 from docutils import core
15 from docutils._compat import b
16 import os
18 class EncodingTestCase(DocutilsTestSupport.StandardTestCase):
20 def test_xmlcharrefreplace(self):
21 # Test that xmlcharrefreplace is the default output encoding
22 # error handler.
23 settings_overrides={
24 'output_encoding': 'latin1',
25 'stylesheet': '',
26 '_disable_config': True,}
27 result = core.publish_string(
28 u'EUR = \u20ac', writer_name='html_plain',
29 settings_overrides=settings_overrides)
30 # Encoding a euro sign with latin1 doesn't work, so the
31 # xmlcharrefreplace handler is used.
32 self.assertIn(b('EUR = €'), result)
34 class MovingArgsTestCase(DocutilsTestSupport.StandardTestCase):
36 settings_overrides={'stylesheet_path': '',
37 # 'embed_stylesheet': False,
38 '_disable_config': True,
41 def test_definition_list_item_classes(self):
42 # Do not drop class arguments for the definition list item.
43 # Pass them to the term node instead.
44 data = """\
45 first term:
46 fist def
48 .. class:: for the second item
50 second term:
51 second def
52 """
53 result = core.publish_string(data, writer_name='html_plain',
54 settings_overrides=self.settings_overrides)
55 self.assertIn(b('<dt class="for the second item">second term:</dt>'),
56 result)
58 def test_definition_list_item_name(self):
59 # Do not drop the "name" of the definition list item.
60 # Pass it to to the term node instead.
61 data = """\
62 first term:
63 first def
65 .. _second item:
67 second term:
68 second def
69 """
70 result = core.publish_string(data, writer_name='html_plain',
71 settings_overrides=self.settings_overrides)
72 self.assertIn(b('<dt id="second-item">second term:</dt>'),
73 result)
76 class SettingsTestCase(DocutilsTestSupport.StandardTestCase):
77 data = 'test'
79 def test_default_stylesheet(self):
80 # default style sheet, embedded
81 mysettings = {'_disable_config': True,}
82 styles = core.publish_parts(self.data, writer_name='html_plain',
83 settings_overrides=mysettings)['stylesheet']
84 self.assertIn('Minimal style sheet '
85 'for the HTML output of Docutils.', styles)
87 def test_default_stylesheet_linked(self):
88 # default style sheet, linked
89 mysettings = {'_disable_config': True,
90 'embed_stylesheet': False}
91 styles = core.publish_parts(self.data, writer_name='html_plain',
92 settings_overrides=mysettings)['stylesheet']
93 self.assertIn('docutils/writers/html_plain/minimal.css', styles)
95 def test_math_stylesheet_linked(self):
96 # default + math style sheet, linked
97 mysettings = {'_disable_config': True,
98 'embed_stylesheet': False,
99 'stylesheet_path': 'minimal.css, math.css'}
100 styles = core.publish_parts(self.data, writer_name='html_plain',
101 settings_overrides=mysettings)['stylesheet']
102 self.assertIn('docutils/writers/html_plain/minimal.css', styles)
103 self.assertIn('docutils/writers/html_plain/math.css', styles)
105 def test_custom_stylesheet_linked(self):
106 # default + custom style sheet, linked
107 mysettings = {'_disable_config': True,
108 'embed_stylesheet': False,
109 'stylesheet_path': 'minimal.css, '
110 'data/ham.css'}
111 styles = core.publish_parts(self.data, writer_name='html_plain',
112 settings_overrides=mysettings)['stylesheet']
113 self.assertIn('docutils/writers/html_plain/minimal.css', styles)
114 self.assertIn('href="data/ham.css"', styles)
116 def test_custom_stylesheet_dir(self):
117 mysettings = {'_disable_config': True,
118 'embed_stylesheet': False,
119 'stylesheet_dirs': ('../docutils/writers/html_plain/',
120 'data'),
121 'stylesheet_path': 'minimal.css, ham.css'}
122 styles = core.publish_parts(self.data, writer_name='html_plain',
123 settings_overrides=mysettings)['stylesheet']
124 if os.path.isdir('../docutils/writers/html_plain/'):
125 self.assertIn('docutils/writers/html_plain/minimal.css', styles)
126 self.assertIn('href="data/ham.css"', styles)
128 def test_custom_stylesheet_dir_embedded(self):
129 mysettings = {'_disable_config': True,
130 'embed_stylesheet': True,
131 'stylesheet_dirs': ('../docutils/writers/html_plain/',
132 'data'),
133 'stylesheet_path': 'ham.css'}
134 styles = core.publish_parts(self.data, writer_name='html_plain',
135 settings_overrides=mysettings)['stylesheet']
136 self.assertIn('dl.docutils dd {\n margin-bottom: 0.5em }', styles)
138 class MathTestCase(DocutilsTestSupport.StandardTestCase):
140 """Attention: This class tests the current implementation of maths support
141 which is open to change in future Docutils releases. """
143 mathjax_script = '<script type="text/javascript" src="%s">'
144 default_mathjax_url = ('https://cdn.mathjax.org/mathjax/latest/MathJax.js'
145 '?config=TeX-AMS_CHTML')
146 custom_mathjax_url = ('file:///usr/share/javascript/mathjax/MathJax.js'
147 '?config=TeX-AMS-MML_HTMLorMML')
148 data = ':math:`42`'
150 def test_math_output_default(self):
151 # HTML with math.css stylesheet (since 0.11)
152 mysettings = {'_disable_config': True,}
153 styles = core.publish_parts(self.data, writer_name='html_plain',
154 settings_overrides=mysettings)['stylesheet']
155 self.assertIn('convert LaTeX equations to HTML output.', styles)
157 def test_math_output_mathjax(self):
158 # Explicitly specifying math_output=MathJax, case insensitively
159 # use default MathJax URL
160 mysettings = {'_disable_config': True,
161 'math_output': 'MathJax'}
162 head = core.publish_parts(self.data, writer_name='html_plain',
163 settings_overrides=mysettings)['head']
164 self.assertIn(self.mathjax_script % self.default_mathjax_url, head)
166 def test_math_output_mathjax_custom(self):
167 # Customizing MathJax URL
168 mysettings = {'_disable_config': True,
169 'math_output':
170 'mathjax %s' % self.custom_mathjax_url}
171 head = core.publish_parts(self.data, writer_name='html_plain',
172 settings_overrides=mysettings)['head']
173 self.assertIn(self.mathjax_script % self.custom_mathjax_url, head)
175 def test_math_output_html(self):
176 mysettings = {'_disable_config': True,
177 'math_output': 'HTML'}
178 head = core.publish_parts(self.data, writer_name='html_plain',
179 settings_overrides=mysettings)['head']
180 # There should be no MathJax script when math_output is not MathJax
181 self.assertNotIn('MathJax.js', head)
183 def test_math_output_html_stylesheet(self):
184 mysettings = {'_disable_config': True,
185 'math_output': 'HTML math.css,custom/style.css',
186 'stylesheet_dirs': ('.', 'functional/input/data'),
187 'embed_stylesheet': False}
188 styles = core.publish_parts(self.data, writer_name='html_plain',
189 settings_overrides=mysettings)['stylesheet']
190 self.assertEqual(u"""\
191 <link rel="stylesheet" href="functional/input/data/minimal.css" type="text/css" />
192 <link rel="stylesheet" href="functional/input/data/plain.css" type="text/css" />
193 <link rel="stylesheet" href="functional/input/data/math.css" type="text/css" />
194 <link rel="stylesheet" href="custom/style.css" type="text/css" />
195 """, styles)
197 def test_math_output_mathjax_no_math(self):
198 mysettings = {'_disable_config': True,
199 'math_output': 'MathJax'}
200 # There should be no math script when text does not contain math
201 head = core.publish_parts('No math.', writer_name='html_plain')['head']
202 self.assertNotIn('MathJax', head)
205 if __name__ == '__main__':
206 import unittest
207 unittest.main()