summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_minidom.py2
-rw-r--r--Lib/test/test_sax.py17
-rw-r--r--Lib/test/test_xml_etree.py45
-rw-r--r--Lib/test/test_xml_etree_c.py5
-rw-r--r--Lib/test/xmltestdata/simple-ns.xml (renamed from Lib/test/samples/simple-ns.xml)0
-rw-r--r--Lib/test/xmltestdata/simple.xml (renamed from Lib/test/samples/simple.xml)0
-rw-r--r--Lib/test/xmltestdata/test.xml (renamed from Lib/test/test.xml)0
-rw-r--r--Lib/test/xmltestdata/test.xml.out (renamed from Lib/test/test.xml.out)0
8 files changed, 41 insertions, 28 deletions
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py
index 7ccb8f4..a8c0b10 100644
--- a/Lib/test/test_minidom.py
+++ b/Lib/test/test_minidom.py
@@ -19,7 +19,7 @@ if __name__ == "__main__":
base = sys.argv[0]
else:
base = __file__
-tstfile = os.path.join(os.path.dirname(base), "test"+os.extsep+"xml")
+tstfile = os.path.join(os.path.dirname(base), "xmltestdata", "test.xml")
del base
# The tests of DocumentType importing use these helpers to construct
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
index c582985..22048e6 100644
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -17,6 +17,9 @@ from test.test_support import findfile, run_unittest
import unittest
import os
+TEST_XMLFILE = findfile(os.path.join("xmltestdata", "test.xml"))
+TEST_XMLFILE_OUT = findfile(os.path.join("xmltestdata", "test.xml.out"))
+
ns_uri = "http://www.python.org/xml-ns/saxtest/"
class XmlTestBase(unittest.TestCase):
@@ -311,7 +314,7 @@ class XMLFilterBaseTest(unittest.TestCase):
#
# ===========================================================================
-xml_test_out = open(findfile("test"+os.extsep+"xml"+os.extsep+"out")).read()
+xml_test_out = open(TEST_XMLFILE_OUT).read()
class ExpatReaderTest(XmlTestBase):
@@ -323,7 +326,7 @@ class ExpatReaderTest(XmlTestBase):
xmlgen = XMLGenerator(result)
parser.setContentHandler(xmlgen)
- parser.parse(open(findfile("test"+os.extsep+"xml")))
+ parser.parse(open(TEST_XMLFILE))
self.assertEquals(result.getvalue(), xml_test_out)
@@ -452,7 +455,7 @@ class ExpatReaderTest(XmlTestBase):
xmlgen = XMLGenerator(result)
parser.setContentHandler(xmlgen)
- parser.parse(findfile("test"+os.extsep+"xml"))
+ parser.parse(TEST_XMLFILE)
self.assertEquals(result.getvalue(), xml_test_out)
@@ -462,7 +465,7 @@ class ExpatReaderTest(XmlTestBase):
xmlgen = XMLGenerator(result)
parser.setContentHandler(xmlgen)
- parser.parse(InputSource(findfile("test"+os.extsep+"xml")))
+ parser.parse(InputSource(TEST_XMLFILE))
self.assertEquals(result.getvalue(), xml_test_out)
@@ -473,7 +476,7 @@ class ExpatReaderTest(XmlTestBase):
parser.setContentHandler(xmlgen)
inpsrc = InputSource()
- inpsrc.setByteStream(open(findfile("test"+os.extsep+"xml")))
+ inpsrc.setByteStream(open(TEST_XMLFILE))
parser.parse(inpsrc)
self.assertEquals(result.getvalue(), xml_test_out)
@@ -534,9 +537,9 @@ class ExpatReaderTest(XmlTestBase):
xmlgen = XMLGenerator(result)
parser = create_parser()
parser.setContentHandler(xmlgen)
- parser.parse(findfile("test.xml"))
+ parser.parse(TEST_XMLFILE)
- self.assertEquals(parser.getSystemId(), findfile("test.xml"))
+ self.assertEquals(parser.getSystemId(), TEST_XMLFILE)
self.assertEquals(parser.getPublicId(), None)
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index bc8b620..b99e42a 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -17,6 +17,9 @@ from test import test_support
from xml.etree import ElementTree as ET
+SIMPLE_XMLFILE = "xmltestdata/simple.xml"
+SIMPLE_NS_XMLFILE = "xmltestdata/simple-ns.xml"
+
SAMPLE_XML = """\
<body>
<tag class='a'>text</tag>
@@ -418,7 +421,7 @@ def file_init():
>>> tree.find("section/tag").tag
'tag'
- >>> tree = ET.ElementTree(file="samples/simple.xml")
+ >>> tree = ET.ElementTree(file=SIMPLE_XMLFILE)
>>> tree.find("element").tag
'element'
>>> tree.find("element/../empty-element").tag
@@ -564,7 +567,7 @@ def parsefile():
"""
Test parsing from file.
- >>> tree = ET.parse("samples/simple.xml")
+ >>> tree = ET.parse(SIMPLE_XMLFILE)
>>> normalize_crlf(tree)
>>> tree.write(sys.stdout)
<root>
@@ -572,7 +575,7 @@ def parsefile():
<element>text</element>tail
<empty-element />
</root>
- >>> tree = ET.parse("samples/simple-ns.xml")
+ >>> tree = ET.parse(SIMPLE_NS_XMLFILE)
>>> normalize_crlf(tree)
>>> tree.write(sys.stdout)
<ns0:root xmlns:ns0="namespace">
@@ -584,7 +587,7 @@ def parsefile():
>>> parser = ET.XMLParser()
>>> parser.version # XXX: Upgrade to 2.0.1?
'Expat 2.0.0'
- >>> parser.feed(open("samples/simple.xml").read())
+ >>> parser.feed(open(SIMPLE_XMLFILE).read())
>>> print serialize(parser.close())
<root>
<element key="value">text</element>
@@ -593,7 +596,7 @@ def parsefile():
</root>
>>> parser = ET.XMLTreeBuilder() # 1.2 compatibility
- >>> parser.feed(open("samples/simple.xml").read())
+ >>> parser.feed(open(SIMPLE_XMLFILE).read())
>>> print serialize(parser.close())
<root>
<element key="value">text</element>
@@ -603,7 +606,7 @@ def parsefile():
>>> target = ET.TreeBuilder()
>>> parser = ET.XMLParser(target=target)
- >>> parser.feed(open("samples/simple.xml").read())
+ >>> parser.feed(open(SIMPLE_XMLFILE).read())
>>> print serialize(parser.close())
<root>
<element key="value">text</element>
@@ -644,7 +647,7 @@ def iterparse():
>>> iterparse = ET.iterparse
- >>> context = iterparse("samples/simple.xml")
+ >>> context = iterparse(SIMPLE_XMLFILE)
>>> action, elem = next(context)
>>> print action, elem.tag
end element
@@ -656,7 +659,7 @@ def iterparse():
>>> context.root.tag
'root'
- >>> context = iterparse("samples/simple-ns.xml")
+ >>> context = iterparse(SIMPLE_NS_XMLFILE)
>>> for action, elem in context:
... print action, elem.tag
end {namespace}element
@@ -665,17 +668,17 @@ def iterparse():
end {namespace}root
>>> events = ()
- >>> context = iterparse("samples/simple.xml", events)
+ >>> context = iterparse(SIMPLE_XMLFILE, events)
>>> for action, elem in context:
... print action, elem.tag
>>> events = ()
- >>> context = iterparse("samples/simple.xml", events=events)
+ >>> context = iterparse(SIMPLE_XMLFILE, events=events)
>>> for action, elem in context:
... print action, elem.tag
>>> events = ("start", "end")
- >>> context = iterparse("samples/simple.xml", events)
+ >>> context = iterparse(SIMPLE_XMLFILE, events)
>>> for action, elem in context:
... print action, elem.tag
start root
@@ -688,7 +691,7 @@ def iterparse():
end root
>>> events = ("start", "end", "start-ns", "end-ns")
- >>> context = iterparse("samples/simple-ns.xml", events)
+ >>> context = iterparse(SIMPLE_NS_XMLFILE, events)
>>> for action, elem in context:
... if action in ("start", "end"):
... print action, elem.tag
@@ -706,7 +709,7 @@ def iterparse():
end-ns None
>>> events = ("start", "end", "bogus")
- >>> context = iterparse("samples/simple.xml", events)
+ >>> context = iterparse(SIMPLE_XMLFILE, events)
Traceback (most recent call last):
ValueError: unknown event 'bogus'
@@ -767,7 +770,7 @@ def custom_builder():
... pass
>>> builder = Builder()
>>> parser = ET.XMLParser(target=builder)
- >>> parser.feed(open("samples/simple.xml", "r").read())
+ >>> parser.feed(open(SIMPLE_XMLFILE, "r").read())
start root
start element
end element
@@ -790,7 +793,7 @@ def custom_builder():
... print "comment", repr(data)
>>> builder = Builder()
>>> parser = ET.XMLParser(target=builder)
- >>> parser.feed(open("samples/simple-ns.xml", "r").read())
+ >>> parser.feed(open(SIMPLE_NS_XMLFILE, "r").read())
pi pi 'data'
comment ' comment '
start {namespace}root
@@ -808,7 +811,7 @@ def getchildren():
"""
Test Element.getchildren()
- >>> tree = ET.parse(open("samples/simple.xml", "r"))
+ >>> tree = ET.parse(open(SIMPLE_XMLFILE, "r"))
>>> for elem in tree.getroot().iter():
... summarize_list(elem.getchildren())
['element', 'element', 'empty-element']
@@ -1286,9 +1289,9 @@ XINCLUDE["default.xml"] = """\
<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
<p>Example.</p>
- <xi:include href="samples/simple.xml"/>
+ <xi:include href="{}"/>
</document>
-"""
+""".format(SIMPLE_XMLFILE)
def xinclude_loader(href, parse="xml", encoding=None):
try:
@@ -1822,8 +1825,10 @@ def test_main(module_name='xml.etree.ElementTree'):
from test import test_xml_etree
def ignore(message, category=DeprecationWarning):
warnings.filterwarnings("ignore", message, category)
+
# The same doctests are used for both the Python and the C implementations
assert test_xml_etree.ET.__name__ == module_name
+
with warnings.catch_warnings(), CleanContext():
# Search behaviour is broken if search path starts with "/".
ignore("This search is broken in 1.3 and earlier, and will be fixed "
@@ -1838,8 +1843,8 @@ def test_main(module_name='xml.etree.ElementTree'):
test_support.run_doctest(test_xml_etree, verbosity=True)
- # The module should not be changed by the tests
- assert test_xml_etree.ET.__name__ == module_name
+ # The module should not be changed by the tests
+ assert test_xml_etree.ET.__name__ == module_name
if __name__ == '__main__':
test_main()
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py
index 7e978de..78a6a92 100644
--- a/Lib/test/test_xml_etree_c.py
+++ b/Lib/test/test_xml_etree_c.py
@@ -22,13 +22,18 @@ def test_main():
test_support.run_doctest(test_xml_etree_c, verbosity=True)
# Assign the C implementation before running the doctests
+ # Patch the __name__, to prevent confusion with the pure Python test
pyET = test_xml_etree.ET
+ py__name__ = test_xml_etree.__name__
test_xml_etree.ET = cET
+ if __name__ != '__main__':
+ test_xml_etree.__name__ = __name__
try:
# Run the same test suite as xml.etree.ElementTree
test_xml_etree.test_main(module_name='xml.etree.cElementTree')
finally:
test_xml_etree.ET = pyET
+ test_xml_etree.__name__ = py__name__
if __name__ == '__main__':
test_main()
diff --git a/Lib/test/samples/simple-ns.xml b/Lib/test/xmltestdata/simple-ns.xml
index f1f34b2..f1f34b2 100644
--- a/Lib/test/samples/simple-ns.xml
+++ b/Lib/test/xmltestdata/simple-ns.xml
diff --git a/Lib/test/samples/simple.xml b/Lib/test/xmltestdata/simple.xml
index b88c2c7..b88c2c7 100644
--- a/Lib/test/samples/simple.xml
+++ b/Lib/test/xmltestdata/simple.xml
diff --git a/Lib/test/test.xml b/Lib/test/xmltestdata/test.xml
index 9af92fb..9af92fb 100644
--- a/Lib/test/test.xml
+++ b/Lib/test/xmltestdata/test.xml
diff --git a/Lib/test/test.xml.out b/Lib/test/xmltestdata/test.xml.out
index d4ab1ab..d4ab1ab 100644
--- a/Lib/test/test.xml.out
+++ b/Lib/test/xmltestdata/test.xml.out