Added minidom tests.
This commit is contained in:
parent
edd9924474
commit
7993bcc040
|
@ -0,0 +1,64 @@
|
|||
Test Succeeded testAAA
|
||||
Test Succeeded testAAB
|
||||
Test Succeeded testAddAttr
|
||||
Test Succeeded testAppendChild
|
||||
Test Succeeded testAttrListItem
|
||||
Test Succeeded testAttrListItemNS
|
||||
Test Succeeded testAttrListItems
|
||||
Test Succeeded testAttrListKeys
|
||||
Test Succeeded testAttrListKeysNS
|
||||
Test Succeeded testAttrListLength
|
||||
Test Succeeded testAttrListValues
|
||||
Test Succeeded testAttrList__getitem__
|
||||
Test Succeeded testAttrList__setitem__
|
||||
Test Succeeded testAttributeRepr
|
||||
Test Succeeded testChangeAttr
|
||||
Test Succeeded testChildNodes
|
||||
Test Succeeded testCloneAttributeDeep
|
||||
Test Succeeded testCloneAttributeShallow
|
||||
Test Succeeded testCloneDocumentDeep
|
||||
Test Succeeded testCloneDocumentShallow
|
||||
Test Succeeded testCloneElementDeep
|
||||
Test Succeeded testCloneElementShallow
|
||||
Test Succeeded testCloneElementShallowCopiesAttributes
|
||||
Test Succeeded testClonePIDeep
|
||||
Test Succeeded testClonePIShallow
|
||||
Test Succeeded testComment
|
||||
Test Succeeded testCreatAttributeNS
|
||||
Test Succeeded testCreateElementNS
|
||||
Test Succeeded testDeleteAttr
|
||||
Test Succeeded testDocumentElement
|
||||
Test Succeeded testElement
|
||||
Test Succeeded testElementReprAndStr
|
||||
Test Succeeded testFirstChild
|
||||
Test Succeeded testGetAttrLength
|
||||
Test Succeeded testGetAttrList
|
||||
Test Succeeded testGetAttrValues
|
||||
Test Succeeded testGetAttribute
|
||||
Test Succeeded testGetAttributeNS
|
||||
Test Succeeded testGetAttributeNode
|
||||
Test Succeeded testGetElementsByTagName
|
||||
Test Succeeded testGetElementsByTagNameNS
|
||||
Test Succeeded testGetEmptyNodeListFromElementsByTagNameNS
|
||||
Test Succeeded testHasChildNodes
|
||||
Test Succeeded testInsertBefore
|
||||
Test Succeeded testNonZero
|
||||
Test Succeeded testParse
|
||||
Test Succeeded testParseAttributeNamespaces
|
||||
Test Succeeded testParseAttributes
|
||||
Test Succeeded testParseElement
|
||||
Test Succeeded testParseElementNamespaces
|
||||
Test Succeeded testParseProcessingInstructions
|
||||
Test Succeeded testParseString
|
||||
Test Succeeded testProcessingInstruction
|
||||
Test Succeeded testProcessingInstructionRepr
|
||||
Test Succeeded testRemoveAttr
|
||||
Test Succeeded testRemoveAttrNS
|
||||
Test Succeeded testRemoveAttributeNode
|
||||
Test Succeeded testSetAttrValueandNodeValue
|
||||
Test Succeeded testTextNodeRepr
|
||||
Test Succeeded testTextRepr
|
||||
Test Succeeded testTooManyDocumentElements
|
||||
Test Succeeded testUnlink
|
||||
Test Succeeded testWriteText
|
||||
Test Succeeded testWriteXML
|
|
@ -0,0 +1,115 @@
|
|||
<?xml version="1.0"?>
|
||||
<HTML xmlns:pp="http://www.isogen.com/paul/post-processor">
|
||||
<TITLE>Introduction to XSL</TITLE>
|
||||
<H1>Introduction to XSL</H1>
|
||||
|
||||
|
||||
|
||||
<HR/>
|
||||
<H2>Overview
|
||||
</H2>
|
||||
<UL>
|
||||
|
||||
<LI>1.Intro</LI>
|
||||
|
||||
<LI>2.History</LI>
|
||||
|
||||
<LI>3.XSL Basics</LI>
|
||||
|
||||
<LI>Lunch</LI>
|
||||
|
||||
<LI>4.An XML Data Model</LI>
|
||||
|
||||
<LI>5.XSL Patterns</LI>
|
||||
|
||||
<LI>6.XSL Templates</LI>
|
||||
|
||||
<LI>7.XSL Formatting Model
|
||||
</LI>
|
||||
|
||||
</UL>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<HR/>
|
||||
<H2>Intro</H2>
|
||||
<UL>
|
||||
|
||||
<LI>Who am I?</LI>
|
||||
|
||||
<LI>Who are you?</LI>
|
||||
|
||||
<LI>Why are we here?
|
||||
</LI>
|
||||
|
||||
</UL>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<HR/>
|
||||
<H2>History: XML and SGML</H2>
|
||||
<UL>
|
||||
|
||||
<LI>XML is a subset of SGML.</LI>
|
||||
|
||||
<LI>SGML allows the separation of abstract content from formatting.</LI>
|
||||
|
||||
<LI>Also one of XML's primary virtues (in the doc publishing domain).
|
||||
</LI>
|
||||
|
||||
</UL>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<HR/>
|
||||
<H2>History: What are stylesheets?</H2>
|
||||
<UL>
|
||||
|
||||
<LI>Stylesheets specify the formatting of SGML/XML documents.</LI>
|
||||
|
||||
<LI>Stylesheets put the "style" back into documents.</LI>
|
||||
|
||||
<LI>New York Times content+NYT Stylesheet = NYT paper
|
||||
</LI>
|
||||
|
||||
</UL>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<HR/>
|
||||
<H2>History: FOSI</H2>
|
||||
<UL>
|
||||
|
||||
<LI>FOSI: "Formatted Output Specification Instance"
|
||||
<UL>
|
||||
<LI>MIL-STD-28001
|
||||
</LI>
|
||||
|
||||
<LI>FOSI's are SGML documents
|
||||
</LI>
|
||||
|
||||
<LI>A stylesheet for another document
|
||||
</LI>
|
||||
</UL></LI>
|
||||
|
||||
<LI>Obsolete but implemented...
|
||||
</LI>
|
||||
|
||||
</UL>
|
||||
|
||||
|
||||
|
||||
|
||||
</HTML>
|
|
@ -0,0 +1,321 @@
|
|||
from xml.dom.minidom import parse, Node, Document, parseString
|
||||
import traceback, sys
|
||||
|
||||
tstfile="test.xml"
|
||||
|
||||
Node._debug=1
|
||||
|
||||
def testGetElementsByTagName( ):
|
||||
dom=parse( tstfile )
|
||||
assert dom.getElementsByTagName( "LI" )==\
|
||||
dom.documentElement.getElementsByTagName( "LI" )
|
||||
dom.unlink()
|
||||
dom=None
|
||||
assert( len( Node.allnodes ))==0
|
||||
|
||||
def testInsertBefore( ):
|
||||
dom=parse( tstfile )
|
||||
docel=dom.documentElement
|
||||
#docel.insertBefore( dom.createProcessingInstruction("a", "b"),
|
||||
# docel.childNodes[1])
|
||||
|
||||
#docel.insertBefore( dom.createProcessingInstruction("a", "b"),
|
||||
# docel.childNodes[0])
|
||||
|
||||
#assert docel.childNodes[0].target=="a"
|
||||
#assert docel.childNodes[2].target=="a"
|
||||
dom.unlink()
|
||||
del dom
|
||||
del docel
|
||||
assert( len( Node.allnodes ))==0
|
||||
|
||||
def testAppendChild():
|
||||
dom=parse( tstfile )
|
||||
dom.documentElement.appendChild( dom.createComment( u"Hello" ))
|
||||
assert dom.documentElement.childNodes[-1].nodeName=="#comment"
|
||||
assert dom.documentElement.childNodes[-1].data=="Hello"
|
||||
dom.unlink()
|
||||
dom=None
|
||||
assert( len( Node.allnodes ))==0
|
||||
|
||||
def testNonZero():
|
||||
dom=parse( tstfile )
|
||||
assert dom # should not be zero
|
||||
dom.appendChild( dom.createComment( "foo" ) )
|
||||
assert not dom.childNodes[-1].childNodes
|
||||
dom.unlink()
|
||||
dom=None
|
||||
assert( len( Node.allnodes ))==0
|
||||
|
||||
def testUnlink():
|
||||
dom=parse( tstfile )
|
||||
dom.unlink()
|
||||
dom=None
|
||||
assert( len( Node.allnodes ))==0
|
||||
|
||||
def testElement():
|
||||
dom=Document()
|
||||
dom.appendChild( dom.createElement( "abc" ) )
|
||||
assert dom.documentElement
|
||||
dom.unlink()
|
||||
dom=None
|
||||
assert( len( Node.allnodes ))==0
|
||||
|
||||
def testAAA():
|
||||
dom=parseString( "<abc/>" )
|
||||
el=dom.documentElement
|
||||
el.setAttribute( "spam", "jam2" )
|
||||
dom.unlink()
|
||||
dom=None
|
||||
|
||||
def testAAB():
|
||||
dom=parseString( "<abc/>" )
|
||||
el=dom.documentElement
|
||||
el.setAttribute( "spam", "jam" )
|
||||
el.setAttribute( "spam", "jam2" )
|
||||
dom.unlink()
|
||||
dom=None
|
||||
|
||||
def testAddAttr():
|
||||
dom=Document()
|
||||
child=dom.appendChild( dom.createElement( "abc" ) )
|
||||
|
||||
child.setAttribute( "def", "ghi" )
|
||||
assert child.getAttribute( "def" )=="ghi"
|
||||
assert child.attributes["def"].value=="ghi"
|
||||
|
||||
child.setAttribute( "jkl", "mno" )
|
||||
assert child.getAttribute( "jkl" )=="mno"
|
||||
assert child.attributes["jkl"].value=="mno"
|
||||
|
||||
assert len( child.attributes )==2
|
||||
|
||||
child.setAttribute( "def", "newval" )
|
||||
assert child.getAttribute( "def" )=="newval"
|
||||
assert child.attributes["def"].value=="newval"
|
||||
|
||||
assert len( child.attributes )==2
|
||||
|
||||
dom.unlink()
|
||||
dom=None
|
||||
child=None
|
||||
|
||||
def testDeleteAttr():
|
||||
dom=Document()
|
||||
child=dom.appendChild( dom.createElement( "abc" ) )
|
||||
|
||||
assert len( child.attributes)==0
|
||||
child.setAttribute( "def", "ghi" )
|
||||
assert len( child.attributes)==1
|
||||
del child.attributes["def"]
|
||||
assert len( child.attributes)==0
|
||||
dom.unlink()
|
||||
assert( len( Node.allnodes ))==0
|
||||
|
||||
def testRemoveAttr():
|
||||
dom=Document()
|
||||
child=dom.appendChild( dom.createElement( "abc" ) )
|
||||
|
||||
child.setAttribute( "def", "ghi" )
|
||||
assert len( child.attributes)==1
|
||||
child.removeAttribute("def" )
|
||||
assert len( child.attributes)==0
|
||||
|
||||
dom.unlink()
|
||||
|
||||
def testRemoveAttrNS():
|
||||
dom=Document()
|
||||
child=dom.appendChild(
|
||||
dom.createElementNS( "http://www.python.org", "python:abc" ) )
|
||||
child.setAttributeNS( "http://www.w3.org", "xmlns:python",
|
||||
"http://www.python.org" )
|
||||
child.setAttributeNS( "http://www.python.org", "python:abcattr", "foo" )
|
||||
assert len( child.attributes )==2
|
||||
child.removeAttributeNS( "http://www.python.org", "abcattr" )
|
||||
assert len( child.attributes )==1
|
||||
|
||||
dom.unlink()
|
||||
dom=None
|
||||
|
||||
def testRemoveAttributeNode():
|
||||
dom=Document()
|
||||
child=dom.appendChild( dom.createElement( "foo" ) )
|
||||
child.setAttribute( "spam", "jam" )
|
||||
assert len( child.attributes )==1
|
||||
node=child.getAttributeNode( "spam" )
|
||||
child.removeAttributeNode( node )
|
||||
assert len( child.attributes )==0
|
||||
|
||||
dom.unlink()
|
||||
dom=None
|
||||
assert len( Node.allnodes )==0
|
||||
|
||||
def testChangeAttr():
|
||||
dom=parseString( "<abc/>" )
|
||||
el=dom.documentElement
|
||||
el.setAttribute( "spam", "jam" )
|
||||
assert len( el.attributes )==1
|
||||
el.setAttribute( "spam", "bam" )
|
||||
assert len( el.attributes )==1
|
||||
el.attributes["spam"]="ham"
|
||||
assert len( el.attributes )==1
|
||||
el.setAttribute( "spam2", "bam" )
|
||||
assert len( el.attributes )==2
|
||||
el.attributes[ "spam2"]= "bam2"
|
||||
assert len( el.attributes )==2
|
||||
dom.unlink()
|
||||
dom=None
|
||||
assert len( Node.allnodes )==0
|
||||
|
||||
def testGetAttrList():
|
||||
pass
|
||||
|
||||
def testGetAttrValues(): pass
|
||||
|
||||
def testGetAttrLength(): pass
|
||||
|
||||
def testGetAttribute(): pass
|
||||
|
||||
def testGetAttributeNS(): pass
|
||||
|
||||
def testGetAttributeNode(): pass
|
||||
|
||||
def testGetElementsByTagNameNS(): pass
|
||||
|
||||
def testGetEmptyNodeListFromElementsByTagNameNS(): pass
|
||||
|
||||
def testElementReprAndStr():
|
||||
dom=Document()
|
||||
el=dom.appendChild( dom.createElement( "abc" ) )
|
||||
string1=repr( el )
|
||||
string2=str( el )
|
||||
assert string1==string2
|
||||
dom.unlink()
|
||||
|
||||
# commented out until Fredrick's fix is checked in
|
||||
def _testElementReprAndStrUnicode():
|
||||
dom=Document()
|
||||
el=dom.appendChild( dom.createElement( u"abc" ) )
|
||||
string1=repr( el )
|
||||
string2=str( el )
|
||||
assert string1==string2
|
||||
dom.unlink()
|
||||
|
||||
# commented out until Fredrick's fix is checked in
|
||||
def _testElementReprAndStrUnicodeNS():
|
||||
dom=Document()
|
||||
el=dom.appendChild(
|
||||
dom.createElementNS( u"http://www.slashdot.org", u"slash:abc" ))
|
||||
string1=repr( el )
|
||||
string2=str( el )
|
||||
assert string1==string2
|
||||
assert string1.find("slash:abc" )!=-1
|
||||
dom.unlink()
|
||||
|
||||
def testAttributeRepr():
|
||||
dom=Document()
|
||||
el=dom.appendChild( dom.createElement( u"abc" ) )
|
||||
node=el.setAttribute( "abc", "def" )
|
||||
assert str( node ) == repr( node )
|
||||
dom.unlink()
|
||||
|
||||
def testTextNodeRepr(): pass
|
||||
|
||||
def testWriteXML(): pass
|
||||
|
||||
def testProcessingInstruction(): pass
|
||||
|
||||
def testProcessingInstructionRepr(): pass
|
||||
|
||||
def testTextRepr(): pass
|
||||
|
||||
def testWriteText(): pass
|
||||
|
||||
def testDocumentElement(): pass
|
||||
|
||||
def testTooManyDocumentElements(): pass
|
||||
|
||||
def testCreateElementNS(): pass
|
||||
|
||||
def testCreatAttributeNS(): pass
|
||||
|
||||
def testParse(): pass
|
||||
|
||||
def testParseString(): pass
|
||||
|
||||
def testComment(): pass
|
||||
|
||||
def testAttrListItem(): pass
|
||||
|
||||
def testAttrListItems(): pass
|
||||
|
||||
def testAttrListItemNS(): pass
|
||||
|
||||
def testAttrListKeys(): pass
|
||||
|
||||
def testAttrListKeysNS(): pass
|
||||
|
||||
def testAttrListValues(): pass
|
||||
|
||||
def testAttrListLength(): pass
|
||||
|
||||
def testAttrList__getitem__(): pass
|
||||
|
||||
def testAttrList__setitem__(): pass
|
||||
|
||||
def testSetAttrValueandNodeValue(): pass
|
||||
|
||||
def testParseElement(): pass
|
||||
|
||||
def testParseAttributes(): pass
|
||||
|
||||
def testParseElementNamespaces(): pass
|
||||
|
||||
def testParseAttributeNamespaces(): pass
|
||||
|
||||
def testParseProcessingInstructions(): pass
|
||||
|
||||
def testChildNodes(): pass
|
||||
|
||||
def testFirstChild(): pass
|
||||
|
||||
def testHasChildNodes(): pass
|
||||
|
||||
def testCloneElementShallow(): pass
|
||||
|
||||
def testCloneElementShallowCopiesAttributes(): pass
|
||||
|
||||
def testCloneElementDeep(): pass
|
||||
|
||||
def testCloneDocumentShallow(): pass
|
||||
|
||||
def testCloneDocumentDeep(): pass
|
||||
|
||||
def testCloneAttributeShallow(): pass
|
||||
|
||||
def testCloneAttributeDeep(): pass
|
||||
|
||||
def testClonePIShallow(): pass
|
||||
|
||||
def testClonePIDeep(): pass
|
||||
|
||||
|
||||
names=globals().keys()
|
||||
names.sort()
|
||||
for name in names:
|
||||
if name.startswith( "test" ):
|
||||
func=globals()[name]
|
||||
try:
|
||||
func()
|
||||
print "Test Succeeded", name
|
||||
if len( Node.allnodes ):
|
||||
print "Garbage left over:"
|
||||
print Node.allnodes.items()[0:10]
|
||||
Node.allnodes={}
|
||||
except Exception, e :
|
||||
print "Test Failed: ", name
|
||||
apply( traceback.print_exception, sys.exc_info() )
|
||||
print `e`
|
||||
Node.allnodes={}
|
||||
raise
|
||||
|
Loading…
Reference in New Issue