[Zope3-checkins] CVS: zopeproducts/xml/dom/tests - test_printer.py:1.1
Philipp von Weitershausen
philikon@philikon.de
Fri, 20 Jun 2003 19:40:41 -0400
Update of /cvs-repository/zopeproducts/xml/dom/tests
In directory cvs.zope.org:/tmp/cvs-serv13468/dom/tests
Added Files:
test_printer.py
Log Message:
Ported ParsedXML's PrettyPrinter over, now with interface and unit tests of
course.
=== Added File zopeproducts/xml/dom/tests/test_printer.py ===
##############################################################################
#
# Copyright (c) 2001-2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: test_printer.py,v 1.1 2003/06/20 23:40:40 philikon Exp $
"""
import unittest
from StringIO import StringIO
from zopeproducts.xml.dom.printer import Printer
from zopeproducts.xml.dom import expatbuilder
class DOMPrinterTests(unittest.TestCase):
def setUp(self):
self.xmltext = '<?xml version="1.0" ?>\n<doc>' \
'<bla><singleton/>&</bla></doc>\n'
f = StringIO(self.xmltext)
self.doc = expatbuilder.parse(f)
self.out = StringIO()
def tearDown(self):
pass
def test_print(self):
# test regular print
out = self.out
printer = Printer()
printer.render(out, self.doc)
out.seek(0)
result = out.read()
self.assertEqual(result, self.xmltext)
def test_prettyprint(self):
# test pretty print
out = self.out
printer = Printer(prettyPrint=True, indentLevel=3)
printer.render(out, self.doc)
out.seek(0)
result = out.read()
expected = """\
<?xml version="1.0" ?>
<doc>
<bla>
<singleton/>&
</bla>
</doc>
"""
self.assertEqual(result, expected)
def test_html(self):
# test html output
out = self.out
printer = Printer(html=True)
printer.render(out, self.doc)
out.seek(0)
result = out.read()
expected = '<doc><bla><singleton></singleton>&</bla></doc>\n'
self.assertEqual(result, expected)
def test_entrefexp(self):
# test entity reference expansion
out = self.out
printer = Printer(entityReferenceExpansion=True)
printer.render(out, self.doc)
out.seek(0)
result = out.read()
# XXX this doesn't work as expected (I'd expect & instead of &)
# maybe we have to declare the entity first?
expected = '<?xml version="1.0" ?>\n<doc>' \
'<bla><singleton/>&</bla></doc>\n'
self.assertEqual(result, expected)
def test_suite():
return unittest.makeSuite(DOMPrinterTests)