All Downloads are FREE. Search and download functionalities are using the official Maven repository.

build.test.test_writers.test_docutils_xml.py Maven / Gradle / Ivy

There is a newer version: 2.4
Show newest version
#!/usr/bin/env python

# $Id: test_docutils_xml.py 5889 2009-04-01 20:00:21Z gbrandl $
# Author: Lea Wiemann 
# Copyright: This module has been placed in the public domain.

"""
Test for docutils XML writer.
"""

from __init__ import DocutilsTestSupport

import docutils
import docutils.core
from docutils._compat import b


class DocutilsXMLTestCase(DocutilsTestSupport.StandardTestCase):

    input = b("""\
Test

----------

Test. \xc3\xa4\xc3\xb6\xc3\xbc\xe2\x82\xac""")
    xmldecl = b('\n')
    doctypedecl = b('\n')
    generatedby = b('\n' % docutils.__version__)
    bodynormal = b('TestTest. \xe4\xf6\xfc€')
    bodynewlines = b("""\


Test



Test. \xe4\xf6\xfc€


""")
    bodyindents = b("""\

    
        Test
    
    
    
        Test. \xe4\xf6\xfc€
    

""")

    def test_publish(self):
        settings = {'input_encoding': 'utf8',
                    'output_encoding': 'iso-8859-1',
                    '_disable_config': 1}
        for settings['newlines'] in 0, 1:
            for settings['indents'] in 0, 1:
                for settings['xml_declaration'] in 0, 1:
                    for settings['doctype_declaration'] in 0, 1:

                        expected = b('')
                        if settings['xml_declaration']:
                            expected += self.xmldecl
                        if settings['doctype_declaration']:
                            expected += self.doctypedecl
                        expected += self.generatedby
                        if settings['indents']:
                            expected += self.bodyindents
                        elif settings['newlines']:
                            expected += self.bodynewlines
                        else:
                            expected += self.bodynormal

                        self.assertEqual(docutils.core.publish_string
                                         (source=self.input,
                                          reader_name='standalone',
                                          writer_name='docutils_xml',
                                          settings_overrides=settings),
                                         expected)


if __name__ == '__main__':
    import unittest
    unittest.main()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy