From 1867aa887538dde49fbdcbad87533aec3f4dcb99 Mon Sep 17 00:00:00 2001 From: milde Date: Thu, 25 Oct 2012 11:48:32 +0000 Subject: [PATCH] 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 --- docutils/writers/html4css1/__init__.py | 12 +++---- test/DocutilsTestSupport.py | 20 ++++++++--- test/test_writers/test_html4css1_misc.py | 59 ++++++++++++++++++++++++++++++-- 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/docutils/writers/html4css1/__init__.py b/docutils/writers/html4css1/__init__.py index acc11aa1d..1ea34dd76 100644 --- a/docutils/writers/html4css1/__init__.py +++ b/docutils/writers/html4css1/__init__.py @@ -298,11 +298,8 @@ class HTMLTranslator(nodes.NodeVisitor): self.section_level = 0 self.initial_header_level = int(settings.initial_header_level) - self.math_output = settings.math_output.split(None, 1) - if len(self.math_output) == 2: - self.math_output_option = self.math_output[1] - else: - self.math_output_option = None + self.math_output = settings.math_output.split() + self.math_output_options = self.math_output[1:] self.math_output = self.math_output[0].lower() # A heterogenous stack used in conjunction with the tree traversal. @@ -1206,8 +1203,9 @@ class HTMLTranslator(nodes.NodeVisitor): if self.math_output in ('latex', 'mathjax'): math_code = self.encode(math_code) if self.math_output == 'mathjax': - self.math_header = self.mathjax_script % ( - self.math_output_option or self.mathjax_url) + if self.math_output_options: + self.mathjax_url = self.math_output_options[0] + self.math_header = self.mathjax_script % self.mathjax_url elif self.math_output == 'html': math_code = math2html(math_code) elif self.math_output == 'mathml': 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 = '