""" $Id: XMLNodeUnit.py,v 1.1 2000/10/05 17:47:10 kmacleod Exp $ """ import unittest import string import Orchard.XML import types class XMLNodeUnitTestCase(unittest.TestCase): # # Check constructors # def checkDocumentConstructor(self): document = Orchard.XML.Document() assert document.node_type is Orchard.XML.DocumentType def checkElementConstructor(self): element = Orchard.XML.Element( name='foo' ) assert element.node_type is Orchard.XML.ElementType def checkAttributeConstructor(self): attribute = Orchard.XML.Attribute( name='foo' ) assert attribute.node_type is Orchard.XML.AttributeType def checkCharactersConstructor(self): characters = Orchard.XML.Characters() assert characters.node_type is Orchard.XML.CharactersType def checkCommentConstructor(self): comment = Orchard.XML.Comment() assert comment.node_type is Orchard.XML.CommentType def checkProcessingInstructionConstructor(self): pi = Orchard.XML.ProcessingInstruction() assert pi.node_type is Orchard.XML.ProcessingInstructionType # # Check default property values # def checkDocumentConstructor(self): document = Orchard.XML.Document() assert type(document.contents) is types.ListType def checkElementConstructor(self): element = Orchard.XML.Element( name='foo' ) assert type(element.contents) is types.ListType assert element.namespace_uri == None def checkAttributeConstructor(self): attribute = Orchard.XML.Attribute( name='foo' ) assert attribute.value == "" assert attribute.namespace_uri == None def checkCharactersConstructor(self): characters = Orchard.XML.Characters() assert characters.data == "" def checkCommentConstructor(self): comment = Orchard.XML.Comment() assert comment.data == "" def checkProcessingInstructionConstructor(self): pi = Orchard.XML.ProcessingInstruction() assert pi.data == "" # # Check default property values don't overwrite explicit values # def checkDocumentConstructor(self): element = Orchard.XML.Element( name='foo' ) document = Orchard.XML.Document( contents=[ element ] ) assert len(document.contents) == 1 def checkElementConstructor(self): inner_element = Orchard.XML.Element( name='foo' ) element = Orchard.XML.Element( name='foo', contents=[ inner_element ], namespace_uri='a:uri' ) assert len(element.contents) == 1 assert element.namespace_uri == 'a:uri' def checkAttributeConstructor(self): attribute = Orchard.XML.Attribute( name='foo', value='foo', namespace_uri='a:uri' ) assert attribute.value == "foo" assert attribute.namespace_uri == 'a:uri' def checkCharactersConstructor(self): characters = Orchard.XML.Characters( data='foo' ) assert characters.data == "foo" def checkCommentConstructor(self): comment = Orchard.XML.Comment( data='foo' ) assert comment.data == "foo" def checkProcessingInstructionConstructor(self): pi = Orchard.XML.ProcessingInstruction( target='foo', data='foo' ) assert pi.target == "foo" assert pi.data == "foo" # # check for missing initializers # def checkElementName(self): try: element = Orchard.XML.Element( ) raise AssertionError, "element creation should not allow missing name or local_name" except TypeError: pass def checkAttributeName(self): try: attribute = Orchard.XML.Attribute( ) raise AssertionError, "attribute creation should not allow missing name or local_name" except TypeError: pass def suite(): return unittest.makeSuite(XMLNodeUnitTestCase,'check') if __name__ == "__main__": unittest.TextTestRunner().run(suite())