[Python-checkins] r46775 - sandbox/trunk/tests/test_saxgen.py
andrew.kuchling
python-checkins at python.org
Fri Jun 9 15:21:08 CEST 2006
Author: andrew.kuchling
Date: Fri Jun 9 15:21:08 2006
New Revision: 46775
Added:
sandbox/trunk/tests/test_saxgen.py (contents, props changed)
Log:
Then I tried writing a fresh set of tests for XMLGenerator using doctest. This test suite is complete, but duplicates the testing performed in test_sax.py. I'll leave this file out of the trunk for now.
Added: sandbox/trunk/tests/test_saxgen.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/tests/test_saxgen.py Fri Jun 9 15:21:08 2006
@@ -0,0 +1,57 @@
+"""Test of the saxutils.XMLGenerator class.
+
+$Id$
+"""
+
+import StringIO
+from test import test_support
+from xmlcore.sax.saxutils import XMLGenerator
+
+def test_basic ():
+ """
+ >>> gen = XMLGenerator()
+ >>> gen.startDocument()
+ <?xml version="1.0" encoding="iso-8859-1"?>
+ >>> gen.startElement('root', dict(attr1='value1', attr2 = '<, >, and &'))
+ <root attr2="<, >, and &" attr1="value1">
+ >>> gen.characters('Paragraph containing <, >, and &')
+ Paragraph containing <, >, and &
+ >>> gen.ignorableWhitespace('\\n\\n')
+ <BLANKLINE>
+ <BLANKLINE>
+ >>> gen.processingInstruction('xml-stylesheet', 'http://example.com/css')
+ <?xml-stylesheet http://example.com/css?>
+ >>> gen.endElement('root')
+ </root>
+ """
+
+def test_ns ():
+ """
+ >>> gen = XMLGenerator()
+ >>> ns_uri = 'http://example.com/xbel'
+ >>> gen.startDocument()
+ <?xml version="1.0" encoding="iso-8859-1"?>
+ >>> gen.startPrefixMapping('xbel', ns_uri)
+ >>> gen.startElementNS((ns_uri, 'xbel'), 'xbel:xbel',
+ ... {(ns_uri, 'version'):'1.0'})
+ <xbel:xbel xmlns:xbel="http://example.com/xbel" xbel:version="1.0">
+ >>> gen.startElementNS((ns_uri, 'title'), 'xbel:title', {})
+ <xbel:title>
+ >>> gen.endElementNS((ns_uri, 'title'), 'xbel:title')
+ </xbel:title>
+ >>> gen.startElementNS((None, 'about'), 'about', {})
+ <about>
+ >>> gen.endElementNS((None, 'about'), 'about')
+ </about>
+ >>> gen.endElementNS((ns_uri, 'xbel'), 'xbel:xbel')
+ </xbel:xbel>
+ >>> gen.endPrefixMapping('xbel')
+ """
+
+def main():
+ from test import test_saxgen
+ test_support.run_doctest(test_saxgen, verbosity=True)
+
+
+if __name__ == '__main__':
+ main()
More information about the Python-checkins
mailing list