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
17 class EncodingTestCase(DocutilsTestSupport
.StandardTestCase
):
19 def test_xmlcharrefreplace(self
):
20 # Test that xmlcharrefreplace is the default output encoding
23 'output_encoding': 'latin1',
25 '_disable_config': True,}
26 result
= core
.publish_string(
27 u
'EUR = \u20ac', writer_name
='html4css1',
28 settings_overrides
=settings_overrides
)
29 # Encoding a euro sign with latin1 doesn't work, so the
30 # xmlcharrefreplace handler is used.
31 self
.assertIn(b('EUR = €'), result
)
33 class SettingsTestCase(DocutilsTestSupport
.StandardTestCase
):
36 def test_default_stylesheet(self
):
37 # default style sheet, embedded
38 mysettings
= {'_disable_config': True,}
39 styles
= core
.publish_parts(self
.data
, writer_name
='html4css1',
40 settings_overrides
=mysettings
)['stylesheet']
41 self
.assertIn('Default cascading style sheet '
42 'for the HTML output of Docutils.', styles
)
44 def test_default_stylesheet_linked(self
):
45 # default style sheet, linked
46 mysettings
= {'_disable_config': True,
47 'embed_stylesheet': False}
48 styles
= core
.publish_parts(self
.data
, writer_name
='html4css1',
49 settings_overrides
=mysettings
)['stylesheet']
50 self
.assertIn('docutils/writers/html4css1/html4css1.css', styles
)
52 def test_math_stylesheet_linked(self
):
53 # default + math style sheet, linked
54 mysettings
= {'_disable_config': True,
55 'embed_stylesheet': False,
56 'stylesheet_path': 'html4css1.css, math.css'}
57 styles
= core
.publish_parts(self
.data
, writer_name
='html4css1',
58 settings_overrides
=mysettings
)['stylesheet']
59 self
.assertIn('docutils/writers/html4css1/html4css1.css', styles
)
60 self
.assertIn('docutils/writers/html4css1/math.css', styles
)
62 def test_custom_stylesheet_linked(self
):
63 # default + custom style sheet, linked
64 mysettings
= {'_disable_config': True,
65 'embed_stylesheet': False,
66 'stylesheet_path': 'html4css1.css, '
68 styles
= core
.publish_parts(self
.data
, writer_name
='html4css1',
69 settings_overrides
=mysettings
)['stylesheet']
70 self
.assertIn('docutils/writers/html4css1/html4css1.css', styles
)
71 self
.assertIn('href="data/ham.css"', styles
)
73 def test_custom_stylesheet_dir(self
):
74 mysettings
= {'_disable_config': True,
75 'embed_stylesheet': False,
76 'stylesheet_dirs': ('../docutils/writers/html4css1/',
78 'stylesheet_path': 'html4css1.css, ham.css'}
79 styles
= core
.publish_parts(self
.data
, writer_name
='html4css1',
80 settings_overrides
=mysettings
)['stylesheet']
81 self
.assertIn('docutils/writers/html4css1/html4css1.css', styles
)
82 self
.assertIn('href="data/ham.css"', styles
)
84 class MathTestCase(DocutilsTestSupport
.StandardTestCase
):
86 """Attention: This class tests the current implementation of maths support
87 which is open to change in future Docutils releases. """
89 mathjax_script
= '<script type="text/javascript" src="%s">'
90 default_mathjax_url
= ('http://cdn.mathjax.org/mathjax/latest/MathJax.js'
91 '?config=TeX-AMS-MML_HTMLorMML')
92 custom_mathjax_url
= ('file:///usr/share/javascript/mathjax/MathJax.js'
93 '?config=TeX-AMS-MML_HTMLorMML')
96 def test_math_output_default(self
):
97 # HTML with math.css stylesheet (since 0.11)
98 mysettings
= {'_disable_config': True,}
99 styles
= core
.publish_parts(self
.data
, writer_name
='html4css1',
100 settings_overrides
=mysettings
)['stylesheet']
101 self
.assertIn('convert LaTeX equations to HTML output.', styles
)
103 def test_math_output_mathjax(self
):
104 # Explicitly specifying math_output=MathJax, case insensitively
105 # use default MathJax URL
106 mysettings
= {'_disable_config': True,
107 'math_output': 'MathJax'}
108 head
= core
.publish_parts(self
.data
, writer_name
='html4css1',
109 settings_overrides
=mysettings
)['head']
110 self
.assertIn(self
.mathjax_script
% self
.default_mathjax_url
, head
)
112 def test_math_output_mathjax_custom(self
):
113 # Customizing MathJax URL
114 mysettings
= {'_disable_config': True,
116 'mathjax %s' % self
.custom_mathjax_url
}
117 head
= core
.publish_parts(self
.data
, writer_name
='html4css1',
118 settings_overrides
=mysettings
)['head']
119 self
.assertIn(self
.mathjax_script
% self
.custom_mathjax_url
, head
)
121 def test_math_output_html(self
):
122 mysettings
= {'_disable_config': True,
123 'math_output': 'HTML'}
124 head
= core
.publish_parts(self
.data
, writer_name
='html4css1',
125 settings_overrides
=mysettings
)['head']
126 # There should be no MathJax script when math_output is not MathJax
127 self
.assertNotIn('MathJax.js', head
)
129 def test_math_output_html_stylesheet(self
):
130 mysettings
= {'_disable_config': True,
131 'math_output': 'HTML math.css,custom/style.css',
132 'stylesheet_dirs': ('.', 'functional/input/data'),
133 'embed_stylesheet': False}
134 styles
= core
.publish_parts(self
.data
, writer_name
='html4css1',
135 settings_overrides
=mysettings
)['stylesheet']
136 self
.assertEqual(u
"""\
137 <link rel="stylesheet" href="functional/input/data/html4css1.css" type="text/css" />
138 <link rel="stylesheet" href="functional/input/data/math.css" type="text/css" />
139 <link rel="stylesheet" href="custom/style.css" type="text/css" />
142 def test_math_output_mathjax_no_math(self
):
143 mysettings
= {'_disable_config': True,
144 'math_output': 'MathJax'}
145 # There should be no math script when text does not contain math
146 head
= core
.publish_parts('No math.', writer_name
='html4css1')['head']
147 self
.assertNotIn('MathJax', head
)
150 if __name__
== '__main__':