HACK around tests that depend on directory contents.
[docutils.git] / test / test_writers / test_html4css1_misc.py
blobe61ded58686a01966102ac7bc0324904dd97ef50
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='html4css1',
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 SettingsTestCase(DocutilsTestSupport.StandardTestCase):
35 data = 'test'
37 def test_default_stylesheet(self):
38 # default style sheet, embedded
39 mysettings = {'_disable_config': True,}
40 styles = core.publish_parts(self.data, writer_name='html4css1',
41 settings_overrides=mysettings)['stylesheet']
42 self.assertIn('Default cascading style sheet '
43 'for the HTML output of Docutils.', styles)
45 def test_default_stylesheet_linked(self):
46 # default style sheet, linked
47 mysettings = {'_disable_config': True,
48 'embed_stylesheet': False}
49 styles = core.publish_parts(self.data, writer_name='html4css1',
50 settings_overrides=mysettings)['stylesheet']
51 self.assertIn('docutils/writers/html4css1/html4css1.css', styles)
53 def test_math_stylesheet_linked(self):
54 # default + math style sheet, linked
55 mysettings = {'_disable_config': True,
56 'embed_stylesheet': False,
57 'stylesheet_path': 'html4css1.css, math.css'}
58 styles = core.publish_parts(self.data, writer_name='html4css1',
59 settings_overrides=mysettings)['stylesheet']
60 self.assertIn('docutils/writers/html4css1/html4css1.css', styles)
61 self.assertIn('docutils/writers/html4css1/math.css', styles)
63 def test_custom_stylesheet_linked(self):
64 # default + custom style sheet, linked
65 mysettings = {'_disable_config': True,
66 'embed_stylesheet': False,
67 'stylesheet_path': 'html4css1.css, '
68 'data/ham.css'}
69 styles = core.publish_parts(self.data, writer_name='html4css1',
70 settings_overrides=mysettings)['stylesheet']
71 self.assertIn('docutils/writers/html4css1/html4css1.css', styles)
72 self.assertIn('href="data/ham.css"', styles)
74 def test_custom_stylesheet_dir(self):
75 mysettings = {'_disable_config': True,
76 'embed_stylesheet': False,
77 'stylesheet_dirs': ('../docutils/writers/html4css1/',
78 'data'),
79 'stylesheet_path': 'html4css1.css, ham.css'}
80 styles = core.publish_parts(self.data, writer_name='html4css1',
81 settings_overrides=mysettings)['stylesheet']
82 if os.path.isdir('../docutils/writers/html4css1/'):
83 self.assertIn('docutils/writers/html4css1/html4css1.css', styles)
84 self.assertIn('href="data/ham.css"', styles)
86 def test_custom_stylesheet_dir_embedded(self):
87 mysettings = {'_disable_config': True,
88 'embed_stylesheet': True,
89 'stylesheet_dirs': ('../docutils/writers/html4css1/',
90 'data'),
91 'stylesheet_path': 'ham.css'}
92 styles = core.publish_parts(self.data, writer_name='html4css1',
93 settings_overrides=mysettings)['stylesheet']
94 self.assertIn('dl.docutils dd {\n margin-bottom: 0.5em }', styles)
96 class MathTestCase(DocutilsTestSupport.StandardTestCase):
98 """Attention: This class tests the current implementation of maths support
99 which is open to change in future Docutils releases. """
101 mathjax_script = '<script type="text/javascript" src="%s">'
102 default_mathjax_url = ('http://cdn.mathjax.org/mathjax/latest/MathJax.js'
103 '?config=TeX-AMS-MML_HTMLorMML')
104 custom_mathjax_url = ('file:///usr/share/javascript/mathjax/MathJax.js'
105 '?config=TeX-AMS-MML_HTMLorMML')
106 data = ':math:`42`'
108 def test_math_output_default(self):
109 # HTML with math.css stylesheet (since 0.11)
110 mysettings = {'_disable_config': True,}
111 styles = core.publish_parts(self.data, writer_name='html4css1',
112 settings_overrides=mysettings)['stylesheet']
113 self.assertIn('convert LaTeX equations to HTML output.', styles)
115 def test_math_output_mathjax(self):
116 # Explicitly specifying math_output=MathJax, case insensitively
117 # use default MathJax URL
118 mysettings = {'_disable_config': True,
119 'math_output': 'MathJax'}
120 head = core.publish_parts(self.data, writer_name='html4css1',
121 settings_overrides=mysettings)['head']
122 self.assertIn(self.mathjax_script % self.default_mathjax_url, head)
124 def test_math_output_mathjax_custom(self):
125 # Customizing MathJax URL
126 mysettings = {'_disable_config': True,
127 'math_output':
128 'mathjax %s' % self.custom_mathjax_url}
129 head = core.publish_parts(self.data, writer_name='html4css1',
130 settings_overrides=mysettings)['head']
131 self.assertIn(self.mathjax_script % self.custom_mathjax_url, head)
133 def test_math_output_html(self):
134 mysettings = {'_disable_config': True,
135 'math_output': 'HTML'}
136 head = core.publish_parts(self.data, writer_name='html4css1',
137 settings_overrides=mysettings)['head']
138 # There should be no MathJax script when math_output is not MathJax
139 self.assertNotIn('MathJax.js', head)
141 def test_math_output_html_stylesheet(self):
142 mysettings = {'_disable_config': True,
143 'math_output': 'HTML math.css,custom/style.css',
144 'stylesheet_dirs': ('.', 'functional/input/data'),
145 'embed_stylesheet': False}
146 styles = core.publish_parts(self.data, writer_name='html4css1',
147 settings_overrides=mysettings)['stylesheet']
148 self.assertEqual(u"""\
149 <link rel="stylesheet" href="functional/input/data/html4css1.css" type="text/css" />
150 <link rel="stylesheet" href="functional/input/data/math.css" type="text/css" />
151 <link rel="stylesheet" href="custom/style.css" type="text/css" />
152 """, styles)
154 def test_math_output_mathjax_no_math(self):
155 mysettings = {'_disable_config': True,
156 'math_output': 'MathJax'}
157 # There should be no math script when text does not contain math
158 head = core.publish_parts('No math.', writer_name='html4css1')['head']
159 self.assertNotIn('MathJax', head)
162 if __name__ == '__main__':
163 import unittest
164 unittest.main()