diff options
author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2012-10-25 11:48:32 +0000 |
---|---|---|
committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2012-10-25 11:48:32 +0000 |
commit | 1867aa887538dde49fbdcbad87533aec3f4dcb99 (patch) | |
tree | 3618467667e990e2a6ab51bb7439ed2ddcfa2bf2 /test | |
parent | faac66c9b0d7a4130f5272fc5e0c91a26842d48a (diff) | |
download | docutils-1867aa887538dde49fbdcbad87533aec3f4dcb99.tar.gz |
Code cleanup and test html math output options.
Based on patch by Dmitry Shachnev.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7534 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'test')
-rw-r--r-- | test/DocutilsTestSupport.py | 20 | ||||
-rwxr-xr-x | test/test_writers/test_html4css1_misc.py | 59 |
2 files changed, 72 insertions, 7 deletions
diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 2988768b6..e410070d4 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -119,16 +119,28 @@ class StandardTestCase(unittest.TestCase): operator. """ if not first == second: - raise self.failureException, \ - (msg or '%s != %s' % _format_str(first, second)) + raise self.failureException, ( + msg or '%s != %s' % _format_str(first, second)) def assertNotEqual(self, first, second, msg=None): """Fail if the two objects are equal as determined by the '==' operator. """ if first == second: - raise self.failureException, \ - (msg or '%s == %s' % _format_str(first, second)) + raise self.failureException, ( + msg or '%s == %s' % _format_str(first, second)) + + # assertIn and assertNotIn: new in Python 2.7: + + def assertIn(self, a, b, msg=None): + if a not in b: + raise self.failureException, ( + msg or '%s not in %s' % _format_str(a, b)) + + def assertNotIn(self, a, b, msg=None): + if a in b: + raise self.failureException, ( + msg or '%s in %s' % _format_str(a, b)) # aliases for assertion methods, deprecated since Python 2.7 diff --git a/test/test_writers/test_html4css1_misc.py b/test/test_writers/test_html4css1_misc.py index e171e52ac..b0f32a351 100755 --- a/test/test_writers/test_html4css1_misc.py +++ b/test/test_writers/test_html4css1_misc.py @@ -1,7 +1,8 @@ #! /usr/bin/env python +# coding: utf-8 # $Id$ -# Author: Lea Wiemann +# Authors: Lea Wiemann, Dmitry Shachnev, Günter Milde # Maintainer: docutils-develop@lists.sourceforge.net # Copyright: This module has been placed in the public domain. @@ -13,7 +14,6 @@ from __init__ import DocutilsTestSupport from docutils import core from docutils._compat import b - class EncodingTestCase(DocutilsTestSupport.StandardTestCase): def test_xmlcharrefreplace(self): @@ -28,7 +28,60 @@ class EncodingTestCase(DocutilsTestSupport.StandardTestCase): settings_overrides=settings_overrides) # Encoding a euro sign with latin1 doesn't work, so the # xmlcharrefreplace handler is used. - self.assertNotEqual(result.find(b('EUR = €')), -1) + self.assertIn(b('EUR = €'), result) + +class MathTestCase(DocutilsTestSupport.StandardTestCase): + + """Attention: This class tests the current implementation of maths support + which is open to change in future Docutils releases. """ + + settings_overrides={'_disable_config': True,} + mathjax_script = '<script type="text/javascript" src="%s">' + default_mathjax_url = ('http://cdn.mathjax.org/mathjax/latest/MathJax.js' + '?config=TeX-AMS-MML_HTMLorMML') + custom_mathjax_url = ('file:///usr/share/javascript/mathjax/MathJax.js' + '?config=TeX-AMS-MML_HTMLorMML') + data = ':math:`42`' + + def test_math_output_default(self): + # Currently MathJax with default URL. Likely to change to HTML! + mysettings = self.settings_overrides + head = core.publish_parts(self.data, writer_name='html4css1', + settings_overrides=mysettings)['head'] + self.assertIn(self.mathjax_script % self.default_mathjax_url, head) + + def test_math_output_mathjax(self): + # Explicitly specifying math_output=MathJax, case insensitively + # use default MathJax URL + mysettings = self.settings_overrides.copy() + mysettings.update({'math_output': 'MathJax'}) + head = core.publish_parts(self.data, writer_name='html4css1', + settings_overrides=mysettings)['head'] + self.assertIn(self.mathjax_script % self.default_mathjax_url, head) + + def test_math_output_mathjax_custom(self): + # Customizing MathJax URL + mysettings = self.settings_overrides.copy() + mysettings.update({'math_output': + 'mathjax %s' % self.custom_mathjax_url}) + head = core.publish_parts(self.data, writer_name='html4css1', + settings_overrides=mysettings)['head'] + self.assertIn(self.mathjax_script % self.custom_mathjax_url, head) + + def test_math_output_html(self): + # There should be no MathJax script when math_output is not MathJax + mysettings = self.settings_overrides.copy() + mysettings.update({'math_output': 'HTML'}) + head = core.publish_parts(self.data, writer_name='html4css1', + settings_overrides=mysettings)['head'] + self.assertNotIn('MathJax.js', head) + + def test_math_output_mathjax_no_math(self): + mysettings = self.settings_overrides.copy() + mysettings.update({'math_output': 'MathJax'}) + # There should be no math script when text does not contain math + head = core.publish_parts('No math.', writer_name='html4css1')['head'] + self.assertNotIn('MathJax', head) if __name__ == '__main__': |