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.
10 Miscellaneous HTML writer tests.
13 from __init__
import DocutilsTestSupport
14 from docutils
import core
15 from docutils
._compat
import b
18 class EncodingTestCase(DocutilsTestSupport
.StandardTestCase
):
20 def test_xmlcharrefreplace(self
):
21 # Test that xmlcharrefreplace is the default output encoding
24 'output_encoding': 'latin1',
26 '_disable_config': True,}
27 result
= core
.publish_string(
28 u
'EUR = \u20ac', writer_name
='html_base',
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 to the term node instead.
48 .. class:: for the second item
53 result
= core
.publish_string(data
, writer_name
='html_base',
54 settings_overrides
=self
.settings_overrides
)
55 self
.assertIn(b('<dt class="for the second item">second term:</dt>'),
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.
70 result
= core
.publish_string(data
, writer_name
='html_base',
71 settings_overrides
=self
.settings_overrides
)
72 self
.assertIn(b('<dt id="second-item">second term:</dt>'),
76 class SettingsTestCase(DocutilsTestSupport
.StandardTestCase
):
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_base',
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_base',
92 settings_overrides
=mysettings
)['stylesheet']
93 self
.assertIn('docutils/writers/html_base/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_base',
101 settings_overrides
=mysettings
)['stylesheet']
102 self
.assertIn('docutils/writers/html_base/minimal.css', styles
)
103 self
.assertIn('docutils/writers/html_base/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, '
111 styles
= core
.publish_parts(self
.data
, writer_name
='html_base',
112 settings_overrides
=mysettings
)['stylesheet']
113 self
.assertIn('docutils/writers/html_base/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_base/',
121 'stylesheet_path': 'minimal.css, ham.css'}
122 styles
= core
.publish_parts(self
.data
, writer_name
='html_base',
123 settings_overrides
=mysettings
)['stylesheet']
124 if os
.path
.isdir('../docutils/writers/html_base/'):
125 self
.assertIn('docutils/writers/html_base/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_base/',
133 'stylesheet_path': 'ham.css'}
134 styles
= core
.publish_parts(self
.data
, writer_name
='html_base',
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
= ('http://cdn.mathjax.org/mathjax/latest/MathJax.js'
145 '?config=TeX-AMS-MML_HTMLorMML')
146 custom_mathjax_url
= ('file:///usr/share/javascript/mathjax/MathJax.js'
147 '?config=TeX-AMS-MML_HTMLorMML')
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_base',
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_base',
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,
170 'mathjax %s' % self
.custom_mathjax_url
}
171 head
= core
.publish_parts(self
.data
, writer_name
='html_base',
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_base',
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_base',
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" />
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_base')['head']
202 self
.assertNotIn('MathJax', head
)
205 if __name__
== '__main__':