diff options
author | Fred Drake <fdrake@acm.org> | 2006-07-29 16:56:15 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2006-07-29 16:56:15 (GMT) |
commit | fbdeaad06910a50d6f05da177949b9a451a1132a (patch) | |
tree | 373bae36b9be6328bc02c6f2a778e76a2f58e7ea /Lib/test | |
parent | c032ee939bae3662017f6ff359fb1ed7d207f3f6 (diff) | |
download | cpython-fbdeaad06910a50d6f05da177949b9a451a1132a.zip cpython-fbdeaad06910a50d6f05da177949b9a451a1132a.tar.gz cpython-fbdeaad06910a50d6f05da177949b9a451a1132a.tar.bz2 |
expunge the xmlcore changes:
41667, 41668 - initial switch to xmlcore
47044 - mention of xmlcore in What's New
50687 - mention of xmlcore in the library reference
re-apply xmlcore changes to xml:
41674 - line ending changes (re-applied manually), directory props
41677 - add cElementTree wrapper
41678 - PSF licensing for etree
41812 - whitespace normalization
42724 - fix svn:eol-style settings
43681, 43682 - remove Python version-compatibility cruft from minidom
46773 - fix encoding of \r\n\t in attr values in saxutils
47269 - added XMLParser alias for cElementTree compatibility
additional tests were added in Lib/test/test_sax.py that failed with
the xmlcore changes; these relate to SF bugs #1511497, #1513611
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_minidom.py | 92 | ||||
-rw-r--r-- | Lib/test/test_sax.py | 75 | ||||
-rw-r--r-- | Lib/test/test_xml_etree.py | 35 | ||||
-rw-r--r-- | Lib/test/test_xml_etree_c.py | 6 |
4 files changed, 124 insertions, 84 deletions
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index b9377ae..a6d309f 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -1,4 +1,4 @@ -# test for xmlcore.dom.minidom +# test for xml.dom.minidom import os import sys @@ -7,12 +7,12 @@ import traceback from StringIO import StringIO from test.test_support import verbose -import xmlcore.dom -import xmlcore.dom.minidom -import xmlcore.parsers.expat +import xml.dom +import xml.dom.minidom +import xml.parsers.expat -from xmlcore.dom.minidom import parse, Node, Document, parseString -from xmlcore.dom.minidom import getDOMImplementation +from xml.dom.minidom import parse, Node, Document, parseString +from xml.dom.minidom import getDOMImplementation if __name__ == "__main__": @@ -138,29 +138,29 @@ def testLegalChildren(): text = dom.createTextNode('text') try: dom.appendChild(text) - except xmlcore.dom.HierarchyRequestErr: pass + except xml.dom.HierarchyRequestErr: pass else: print "dom.appendChild didn't raise HierarchyRequestErr" dom.appendChild(elem) try: dom.insertBefore(text, elem) - except xmlcore.dom.HierarchyRequestErr: pass + except xml.dom.HierarchyRequestErr: pass else: print "dom.appendChild didn't raise HierarchyRequestErr" try: dom.replaceChild(text, elem) - except xmlcore.dom.HierarchyRequestErr: pass + except xml.dom.HierarchyRequestErr: pass else: print "dom.appendChild didn't raise HierarchyRequestErr" nodemap = elem.attributes try: nodemap.setNamedItem(text) - except xmlcore.dom.HierarchyRequestErr: pass + except xml.dom.HierarchyRequestErr: pass else: print "NamedNodeMap.setNamedItem didn't raise HierarchyRequestErr" try: nodemap.setNamedItemNS(text) - except xmlcore.dom.HierarchyRequestErr: pass + except xml.dom.HierarchyRequestErr: pass else: print "NamedNodeMap.setNamedItemNS didn't raise HierarchyRequestErr" @@ -439,7 +439,7 @@ def testProcessingInstruction(): and pi.firstChild is None and pi.lastChild is None and pi.localName is None - and pi.namespaceURI == xmlcore.dom.EMPTY_NAMESPACE) + and pi.namespaceURI == xml.dom.EMPTY_NAMESPACE) def testProcessingInstructionRepr(): pass @@ -454,7 +454,7 @@ def testTooManyDocumentElements(): elem = doc.createElement("extra") try: doc.appendChild(elem) - except xmlcore.dom.HierarchyRequestErr: + except xml.dom.HierarchyRequestErr: pass else: print "Failed to catch expected exception when" \ @@ -491,7 +491,7 @@ def testRemoveNamedItem(): confirm(a1.isSameNode(a2)) try: attrs.removeNamedItem("a") - except xmlcore.dom.NotFoundErr: + except xml.dom.NotFoundErr: pass def testRemoveNamedItemNS(): @@ -503,7 +503,7 @@ def testRemoveNamedItemNS(): confirm(a1.isSameNode(a2)) try: attrs.removeNamedItemNS("http://xml.python.org/", "b") - except xmlcore.dom.NotFoundErr: + except xml.dom.NotFoundErr: pass def testAttrListValues(): pass @@ -682,7 +682,7 @@ def check_import_document(deep, testName): doc2 = parseString("<doc/>") try: doc1.importNode(doc2, deep) - except xmlcore.dom.NotSupportedErr: + except xml.dom.NotSupportedErr: pass else: raise Exception(testName + @@ -705,14 +705,12 @@ def create_nonempty_doctype(): doctype = getDOMImplementation().createDocumentType("doc", None, None) doctype.entities._seq = [] doctype.notations._seq = [] - notation = xmlcore.dom.minidom.Notation( - "my-notation", None, - "http://xml.python.org/notations/my") + notation = xml.dom.minidom.Notation("my-notation", None, + "http://xml.python.org/notations/my") doctype.notations._seq.append(notation) - entity = xmlcore.dom.minidom.Entity( - "my-entity", None, - "http://xml.python.org/entities/my", - "my-notation") + entity = xml.dom.minidom.Entity("my-entity", None, + "http://xml.python.org/entities/my", + "my-notation") entity.version = "1.0" entity.encoding = "utf-8" entity.actualEncoding = "us-ascii" @@ -731,7 +729,7 @@ def testImportDocumentTypeShallow(): target = create_doc_without_doctype() try: imported = target.importNode(src.doctype, 0) - except xmlcore.dom.NotSupportedErr: + except xml.dom.NotSupportedErr: pass else: raise Exception( @@ -742,7 +740,7 @@ def testImportDocumentTypeDeep(): target = create_doc_without_doctype() try: imported = target.importNode(src.doctype, 1) - except xmlcore.dom.NotSupportedErr: + except xml.dom.NotSupportedErr: pass else: raise Exception( @@ -850,7 +848,7 @@ def testNodeListItem(): doc.unlink() def testSAX2DOM(): - from xmlcore.dom import pulldom + from xml.dom import pulldom sax2dom = pulldom.SAX2DOM() sax2dom.startDocument() @@ -940,11 +938,11 @@ def testRenameAttribute(): attr = elem.attributes['a'] # Simple renaming - attr = doc.renameNode(attr, xmlcore.dom.EMPTY_NAMESPACE, "b") + attr = doc.renameNode(attr, xml.dom.EMPTY_NAMESPACE, "b") confirm(attr.name == "b" and attr.nodeName == "b" and attr.localName is None - and attr.namespaceURI == xmlcore.dom.EMPTY_NAMESPACE + and attr.namespaceURI == xml.dom.EMPTY_NAMESPACE and attr.prefix is None and attr.value == "v" and elem.getAttributeNode("a") is None @@ -989,11 +987,11 @@ def testRenameAttribute(): and attrmap[("http://xml.python.org/ns2", "d")].isSameNode(attr)) # Rename back to a simple non-NS node - attr = doc.renameNode(attr, xmlcore.dom.EMPTY_NAMESPACE, "e") + attr = doc.renameNode(attr, xml.dom.EMPTY_NAMESPACE, "e") confirm(attr.name == "e" and attr.nodeName == "e" and attr.localName is None - and attr.namespaceURI == xmlcore.dom.EMPTY_NAMESPACE + and attr.namespaceURI == xml.dom.EMPTY_NAMESPACE and attr.prefix is None and attr.value == "v" and elem.getAttributeNode("a") is None @@ -1007,7 +1005,7 @@ def testRenameAttribute(): try: doc.renameNode(attr, "http://xml.python.org/ns", "xmlns") - except xmlcore.dom.NamespaceErr: + except xml.dom.NamespaceErr: pass else: print "expected NamespaceErr" @@ -1020,11 +1018,11 @@ def testRenameElement(): elem = doc.documentElement # Simple renaming - elem = doc.renameNode(elem, xmlcore.dom.EMPTY_NAMESPACE, "a") + elem = doc.renameNode(elem, xml.dom.EMPTY_NAMESPACE, "a") confirm(elem.tagName == "a" and elem.nodeName == "a" and elem.localName is None - and elem.namespaceURI == xmlcore.dom.EMPTY_NAMESPACE + and elem.namespaceURI == xml.dom.EMPTY_NAMESPACE and elem.prefix is None and elem.ownerDocument.isSameNode(doc)) @@ -1047,11 +1045,11 @@ def testRenameElement(): and elem.ownerDocument.isSameNode(doc)) # Rename back to a simple non-NS node - elem = doc.renameNode(elem, xmlcore.dom.EMPTY_NAMESPACE, "d") + elem = doc.renameNode(elem, xml.dom.EMPTY_NAMESPACE, "d") confirm(elem.tagName == "d" and elem.nodeName == "d" and elem.localName is None - and elem.namespaceURI == xmlcore.dom.EMPTY_NAMESPACE + and elem.namespaceURI == xml.dom.EMPTY_NAMESPACE and elem.prefix is None and elem.ownerDocument.isSameNode(doc)) @@ -1062,15 +1060,15 @@ def checkRenameNodeSharedConstraints(doc, node): # Make sure illegal NS usage is detected: try: doc.renameNode(node, "http://xml.python.org/ns", "xmlns:foo") - except xmlcore.dom.NamespaceErr: + except xml.dom.NamespaceErr: pass else: print "expected NamespaceErr" doc2 = parseString("<doc/>") try: - doc2.renameNode(node, xmlcore.dom.EMPTY_NAMESPACE, "foo") - except xmlcore.dom.WrongDocumentErr: + doc2.renameNode(node, xml.dom.EMPTY_NAMESPACE, "foo") + except xml.dom.WrongDocumentErr: pass else: print "expected WrongDocumentErr" @@ -1078,12 +1076,12 @@ def checkRenameNodeSharedConstraints(doc, node): def testRenameOther(): # We have to create a comment node explicitly since not all DOM # builders used with minidom add comments to the DOM. - doc = xmlcore.dom.minidom.getDOMImplementation().createDocument( - xmlcore.dom.EMPTY_NAMESPACE, "e", None) + doc = xml.dom.minidom.getDOMImplementation().createDocument( + xml.dom.EMPTY_NAMESPACE, "e", None) node = doc.createComment("comment") try: - doc.renameNode(node, xmlcore.dom.EMPTY_NAMESPACE, "foo") - except xmlcore.dom.NotSupportedErr: + doc.renameNode(node, xml.dom.EMPTY_NAMESPACE, "foo") + except xml.dom.NotSupportedErr: pass else: print "expected NotSupportedErr when renaming comment node" @@ -1194,13 +1192,13 @@ def testSchemaType(): # since each supports a different level of DTD information. t = elem.schemaType confirm(t.name is None - and t.namespace == xmlcore.dom.EMPTY_NAMESPACE) + and t.namespace == xml.dom.EMPTY_NAMESPACE) names = "id notid text enum ref refs ent ents nm nms".split() for name in names: a = elem.getAttributeNode(name) t = a.schemaType confirm(hasattr(t, "name") - and t.namespace == xmlcore.dom.EMPTY_NAMESPACE) + and t.namespace == xml.dom.EMPTY_NAMESPACE) def testSetIdAttribute(): doc = parseString("<doc a1='v' a2='w'/>") @@ -1229,7 +1227,7 @@ def testSetIdAttribute(): and a2.isId and not a3.isId) # renaming an attribute should not affect its ID-ness: - doc.renameNode(a2, xmlcore.dom.EMPTY_NAMESPACE, "an") + doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an") confirm(e.isSameNode(doc.getElementById("w")) and a2.isId) @@ -1265,7 +1263,7 @@ def testSetIdAttributeNS(): confirm(not a3.isId) confirm(doc.getElementById("v") is None) # renaming an attribute should not affect its ID-ness: - doc.renameNode(a2, xmlcore.dom.EMPTY_NAMESPACE, "an") + doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an") confirm(e.isSameNode(doc.getElementById("w")) and a2.isId) @@ -1301,7 +1299,7 @@ def testSetIdAttributeNode(): confirm(not a3.isId) confirm(doc.getElementById("v") is None) # renaming an attribute should not affect its ID-ness: - doc.renameNode(a2, xmlcore.dom.EMPTY_NAMESPACE, "an") + doc.renameNode(a2, xml.dom.EMPTY_NAMESPACE, "an") confirm(e.isSameNode(doc.getElementById("w")) and a2.isId) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 246d214..af4c7dd 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -1,17 +1,17 @@ # regression test for SAX 2.0 -*- coding: iso-8859-1 -*- # $Id$ -from xmlcore.sax import make_parser, ContentHandler, \ - SAXException, SAXReaderNotAvailable, SAXParseException +from xml.sax import make_parser, ContentHandler, \ + SAXException, SAXReaderNotAvailable, SAXParseException try: make_parser() except SAXReaderNotAvailable: # don't try to test this module if we cannot create a parser raise ImportError("no XML parsers available") -from xmlcore.sax.saxutils import XMLGenerator, escape, unescape, quoteattr, \ - XMLFilterBase -from xmlcore.sax.expatreader import create_parser -from xmlcore.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl +from xml.sax.saxutils import XMLGenerator, escape, unescape, quoteattr, \ + XMLFilterBase +from xml.sax.expatreader import create_parser +from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl from cStringIO import StringIO from test.test_support import verify, verbose, TestFailed, findfile import os @@ -36,17 +36,17 @@ def test_make_parser2(): # Creating parsers several times in a row should succeed. # Testing this because there have been failures of this kind # before. - from xmlcore.sax import make_parser + from xml.sax import make_parser p = make_parser() - from xmlcore.sax import make_parser + from xml.sax import make_parser p = make_parser() - from xmlcore.sax import make_parser + from xml.sax import make_parser p = make_parser() - from xmlcore.sax import make_parser + from xml.sax import make_parser p = make_parser() - from xmlcore.sax import make_parser + from xml.sax import make_parser p = make_parser() - from xmlcore.sax import make_parser + from xml.sax import make_parser p = make_parser() except: return 0 @@ -108,7 +108,7 @@ def test_make_parser(): try: # Creating a parser should succeed - it should fall back # to the expatreader - p = make_parser(['xmlcore.parsers.no_such_parser']) + p = make_parser(['xml.parsers.no_such_parser']) except: return 0 else: @@ -671,6 +671,55 @@ def test_nsattrs_wattr(): attrs.getQNameByName((ns_uri, "attr")) == "ns:attr" +# During the development of Python 2.5, an attempt to move the "xml" +# package implementation to a new package ("xmlcore") proved painful. +# The goal of this change was to allow applications to be able to +# obtain and rely on behavior in the standard library implementation +# of the XML support without needing to be concerned about the +# availability of the PyXML implementation. +# +# While the existing import hackery in Lib/xml/__init__.py can cause +# PyXML's _xmlpus package to supplant the "xml" package, that only +# works because either implementation uses the "xml" package name for +# imports. +# +# The move resulted in a number of problems related to the fact that +# the import machinery's "package context" is based on the name that's +# being imported rather than the __name__ of the actual package +# containment; it wasn't possible for the "xml" package to be replaced +# by a simple module that indirected imports to the "xmlcore" package. +# +# The following two tests exercised bugs that were introduced in that +# attempt. Keeping these tests around will help detect problems with +# other attempts to provide reliable access to the standard library's +# implementation of the XML support. + +def test_sf_1511497(): + # Bug report: http://www.python.org/sf/1511497 + import sys + old_modules = sys.modules.copy() + for modname in sys.modules.keys(): + if modname.startswith("xml."): + del sys.modules[modname] + try: + import xml.sax.expatreader + module = xml.sax.expatreader + return module.__name__ == "xml.sax.expatreader" + finally: + sys.modules.update(old_modules) + +def test_sf_1513611(): + # Bug report: http://www.python.org/sf/1513611 + sio = StringIO("invalid") + parser = make_parser() + from xml.sax import SAXParseException + try: + parser.parse(sio) + except SAXParseException: + return True + else: + return False + # ===== Main program def make_test_output(): diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 86052d7..1e8aa2d 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -1,4 +1,4 @@ -# xmlcore.etree test. This file contains enough tests to make sure that +# xml.etree test. This file contains enough tests to make sure that # all included components work as they should. For a more extensive # test suite, see the selftest script in the ElementTree distribution. @@ -6,8 +6,6 @@ import doctest, sys from test import test_support -from xmlcore.etree import ElementTree as ET - SAMPLE_XML = """ <body> <tag>text</tag> @@ -32,9 +30,9 @@ def sanity(): """ Import sanity. - >>> from xmlcore.etree import ElementTree - >>> from xmlcore.etree import ElementInclude - >>> from xmlcore.etree import ElementPath + >>> from xml.etree import ElementTree + >>> from xml.etree import ElementInclude + >>> from xml.etree import ElementPath """ def check_method(method): @@ -61,6 +59,8 @@ def interface(): """ Test element tree interface. + >>> from xml.etree import ElementTree as ET + >>> element = ET.Element("tag", key="value") >>> tree = ET.ElementTree(element) @@ -108,6 +108,8 @@ def find(): """ Test find methods (including xpath syntax). + >>> from xml.etree import ElementTree as ET + >>> elem = ET.XML(SAMPLE_XML) >>> elem.find("tag").tag 'tag' @@ -174,6 +176,8 @@ def find(): def parseliteral(): r""" + >>> from xml.etree import ElementTree as ET + >>> element = ET.XML("<html><body>text</body></html>") >>> ET.ElementTree(element).write(sys.stdout) <html><body>text</body></html> @@ -195,19 +199,6 @@ def parseliteral(): 'body' """ -def check_encoding(encoding): - """ - >>> check_encoding("ascii") - >>> check_encoding("us-ascii") - >>> check_encoding("iso-8859-1") - >>> check_encoding("iso-8859-15") - >>> check_encoding("cp437") - >>> check_encoding("mac-roman") - """ - ET.XML( - "<?xml version='1.0' encoding='%s'?><xml />" % encoding - ) - # # xinclude tests (samples from appendix C of the xinclude specification) @@ -282,14 +273,16 @@ def xinclude_loader(href, parse="xml", encoding=None): except KeyError: raise IOError("resource not found") if parse == "xml": - return ET.XML(data) + from xml.etree.ElementTree import XML + return XML(data) return data def xinclude(): r""" Basic inclusion example (XInclude C.1) - >>> from xmlcore.etree import ElementInclude + >>> from xml.etree import ElementTree as ET + >>> from xml.etree import ElementInclude >>> document = xinclude_loader("C1.xml") >>> ElementInclude.include(document, xinclude_loader) diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index 587ea99..56e7fed 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -1,10 +1,10 @@ -# xmlcore.etree test for cElementTree +# xml.etree test for cElementTree import doctest, sys from test import test_support -from xmlcore.etree import cElementTree as ET +from xml.etree import cElementTree as ET SAMPLE_XML = """ <body> @@ -30,7 +30,7 @@ def sanity(): """ Import sanity. - >>> from xmlcore.etree import cElementTree + >>> from xml.etree import cElementTree """ def check_method(method): |