Move the xml test data to their own directory.

This commit is contained in:
Florent Xicluna 2010-03-13 11:18:49 +00:00
parent fce7b86807
commit 13ba1a1c65
10 changed files with 45 additions and 31 deletions

View File

@ -19,7 +19,7 @@ if __name__ == "__main__":
base = sys.argv[0] base = sys.argv[0]
else: else:
base = __file__ 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 del base
# The tests of DocumentType importing use these helpers to construct # The tests of DocumentType importing use these helpers to construct

View File

@ -17,6 +17,9 @@ from test.test_support import findfile, run_unittest
import unittest import unittest
import os 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/" ns_uri = "http://www.python.org/xml-ns/saxtest/"
class XmlTestBase(unittest.TestCase): 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): class ExpatReaderTest(XmlTestBase):
@ -323,7 +326,7 @@ class ExpatReaderTest(XmlTestBase):
xmlgen = XMLGenerator(result) xmlgen = XMLGenerator(result)
parser.setContentHandler(xmlgen) parser.setContentHandler(xmlgen)
parser.parse(open(findfile("test"+os.extsep+"xml"))) parser.parse(open(TEST_XMLFILE))
self.assertEquals(result.getvalue(), xml_test_out) self.assertEquals(result.getvalue(), xml_test_out)
@ -452,7 +455,7 @@ class ExpatReaderTest(XmlTestBase):
xmlgen = XMLGenerator(result) xmlgen = XMLGenerator(result)
parser.setContentHandler(xmlgen) parser.setContentHandler(xmlgen)
parser.parse(findfile("test"+os.extsep+"xml")) parser.parse(TEST_XMLFILE)
self.assertEquals(result.getvalue(), xml_test_out) self.assertEquals(result.getvalue(), xml_test_out)
@ -462,7 +465,7 @@ class ExpatReaderTest(XmlTestBase):
xmlgen = XMLGenerator(result) xmlgen = XMLGenerator(result)
parser.setContentHandler(xmlgen) parser.setContentHandler(xmlgen)
parser.parse(InputSource(findfile("test"+os.extsep+"xml"))) parser.parse(InputSource(TEST_XMLFILE))
self.assertEquals(result.getvalue(), xml_test_out) self.assertEquals(result.getvalue(), xml_test_out)
@ -473,7 +476,7 @@ class ExpatReaderTest(XmlTestBase):
parser.setContentHandler(xmlgen) parser.setContentHandler(xmlgen)
inpsrc = InputSource() inpsrc = InputSource()
inpsrc.setByteStream(open(findfile("test"+os.extsep+"xml"))) inpsrc.setByteStream(open(TEST_XMLFILE))
parser.parse(inpsrc) parser.parse(inpsrc)
self.assertEquals(result.getvalue(), xml_test_out) self.assertEquals(result.getvalue(), xml_test_out)
@ -534,9 +537,9 @@ class ExpatReaderTest(XmlTestBase):
xmlgen = XMLGenerator(result) xmlgen = XMLGenerator(result)
parser = create_parser() parser = create_parser()
parser.setContentHandler(xmlgen) 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) self.assertEquals(parser.getPublicId(), None)

View File

@ -17,6 +17,9 @@ from test import test_support
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
SIMPLE_XMLFILE = "xmltestdata/simple.xml"
SIMPLE_NS_XMLFILE = "xmltestdata/simple-ns.xml"
SAMPLE_XML = """\ SAMPLE_XML = """\
<body> <body>
<tag class='a'>text</tag> <tag class='a'>text</tag>
@ -418,7 +421,7 @@ def file_init():
>>> tree.find("section/tag").tag >>> tree.find("section/tag").tag
'tag' 'tag'
>>> tree = ET.ElementTree(file="samples/simple.xml") >>> tree = ET.ElementTree(file=SIMPLE_XMLFILE)
>>> tree.find("element").tag >>> tree.find("element").tag
'element' 'element'
>>> tree.find("element/../empty-element").tag >>> tree.find("element/../empty-element").tag
@ -564,7 +567,7 @@ def parsefile():
""" """
Test parsing from file. Test parsing from file.
>>> tree = ET.parse("samples/simple.xml") >>> tree = ET.parse(SIMPLE_XMLFILE)
>>> normalize_crlf(tree) >>> normalize_crlf(tree)
>>> tree.write(sys.stdout) >>> tree.write(sys.stdout)
<root> <root>
@ -572,7 +575,7 @@ def parsefile():
<element>text</element>tail <element>text</element>tail
<empty-element /> <empty-element />
</root> </root>
>>> tree = ET.parse("samples/simple-ns.xml") >>> tree = ET.parse(SIMPLE_NS_XMLFILE)
>>> normalize_crlf(tree) >>> normalize_crlf(tree)
>>> tree.write(sys.stdout) >>> tree.write(sys.stdout)
<ns0:root xmlns:ns0="namespace"> <ns0:root xmlns:ns0="namespace">
@ -584,7 +587,7 @@ def parsefile():
>>> parser = ET.XMLParser() >>> parser = ET.XMLParser()
>>> parser.version # XXX: Upgrade to 2.0.1? >>> parser.version # XXX: Upgrade to 2.0.1?
'Expat 2.0.0' 'Expat 2.0.0'
>>> parser.feed(open("samples/simple.xml").read()) >>> parser.feed(open(SIMPLE_XMLFILE).read())
>>> print serialize(parser.close()) >>> print serialize(parser.close())
<root> <root>
<element key="value">text</element> <element key="value">text</element>
@ -593,7 +596,7 @@ def parsefile():
</root> </root>
>>> parser = ET.XMLTreeBuilder() # 1.2 compatibility >>> parser = ET.XMLTreeBuilder() # 1.2 compatibility
>>> parser.feed(open("samples/simple.xml").read()) >>> parser.feed(open(SIMPLE_XMLFILE).read())
>>> print serialize(parser.close()) >>> print serialize(parser.close())
<root> <root>
<element key="value">text</element> <element key="value">text</element>
@ -603,7 +606,7 @@ def parsefile():
>>> target = ET.TreeBuilder() >>> target = ET.TreeBuilder()
>>> parser = ET.XMLParser(target=target) >>> parser = ET.XMLParser(target=target)
>>> parser.feed(open("samples/simple.xml").read()) >>> parser.feed(open(SIMPLE_XMLFILE).read())
>>> print serialize(parser.close()) >>> print serialize(parser.close())
<root> <root>
<element key="value">text</element> <element key="value">text</element>
@ -644,7 +647,7 @@ def iterparse():
>>> iterparse = ET.iterparse >>> iterparse = ET.iterparse
>>> context = iterparse("samples/simple.xml") >>> context = iterparse(SIMPLE_XMLFILE)
>>> action, elem = next(context) >>> action, elem = next(context)
>>> print action, elem.tag >>> print action, elem.tag
end element end element
@ -656,7 +659,7 @@ def iterparse():
>>> context.root.tag >>> context.root.tag
'root' 'root'
>>> context = iterparse("samples/simple-ns.xml") >>> context = iterparse(SIMPLE_NS_XMLFILE)
>>> for action, elem in context: >>> for action, elem in context:
... print action, elem.tag ... print action, elem.tag
end {namespace}element end {namespace}element
@ -665,17 +668,17 @@ def iterparse():
end {namespace}root end {namespace}root
>>> events = () >>> events = ()
>>> context = iterparse("samples/simple.xml", events) >>> context = iterparse(SIMPLE_XMLFILE, events)
>>> for action, elem in context: >>> for action, elem in context:
... print action, elem.tag ... print action, elem.tag
>>> events = () >>> events = ()
>>> context = iterparse("samples/simple.xml", events=events) >>> context = iterparse(SIMPLE_XMLFILE, events=events)
>>> for action, elem in context: >>> for action, elem in context:
... print action, elem.tag ... print action, elem.tag
>>> events = ("start", "end") >>> events = ("start", "end")
>>> context = iterparse("samples/simple.xml", events) >>> context = iterparse(SIMPLE_XMLFILE, events)
>>> for action, elem in context: >>> for action, elem in context:
... print action, elem.tag ... print action, elem.tag
start root start root
@ -688,7 +691,7 @@ def iterparse():
end root end root
>>> events = ("start", "end", "start-ns", "end-ns") >>> 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: >>> for action, elem in context:
... if action in ("start", "end"): ... if action in ("start", "end"):
... print action, elem.tag ... print action, elem.tag
@ -706,7 +709,7 @@ def iterparse():
end-ns None end-ns None
>>> events = ("start", "end", "bogus") >>> events = ("start", "end", "bogus")
>>> context = iterparse("samples/simple.xml", events) >>> context = iterparse(SIMPLE_XMLFILE, events)
Traceback (most recent call last): Traceback (most recent call last):
ValueError: unknown event 'bogus' ValueError: unknown event 'bogus'
@ -767,7 +770,7 @@ def custom_builder():
... pass ... pass
>>> builder = Builder() >>> builder = Builder()
>>> parser = ET.XMLParser(target=builder) >>> parser = ET.XMLParser(target=builder)
>>> parser.feed(open("samples/simple.xml", "r").read()) >>> parser.feed(open(SIMPLE_XMLFILE, "r").read())
start root start root
start element start element
end element end element
@ -790,7 +793,7 @@ def custom_builder():
... print "comment", repr(data) ... print "comment", repr(data)
>>> builder = Builder() >>> builder = Builder()
>>> parser = ET.XMLParser(target=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' pi pi 'data'
comment ' comment ' comment ' comment '
start {namespace}root start {namespace}root
@ -808,7 +811,7 @@ def getchildren():
""" """
Test Element.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(): >>> for elem in tree.getroot().iter():
... summarize_list(elem.getchildren()) ... summarize_list(elem.getchildren())
['element', 'element', 'empty-element'] ['element', 'element', 'empty-element']
@ -1286,9 +1289,9 @@ XINCLUDE["default.xml"] = """\
<?xml version='1.0'?> <?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude"> <document xmlns:xi="http://www.w3.org/2001/XInclude">
<p>Example.</p> <p>Example.</p>
<xi:include href="samples/simple.xml"/> <xi:include href="{}"/>
</document> </document>
""" """.format(SIMPLE_XMLFILE)
def xinclude_loader(href, parse="xml", encoding=None): def xinclude_loader(href, parse="xml", encoding=None):
try: try:
@ -1822,8 +1825,10 @@ def test_main(module_name='xml.etree.ElementTree'):
from test import test_xml_etree from test import test_xml_etree
def ignore(message, category=DeprecationWarning): def ignore(message, category=DeprecationWarning):
warnings.filterwarnings("ignore", message, category) warnings.filterwarnings("ignore", message, category)
# The same doctests are used for both the Python and the C implementations # The same doctests are used for both the Python and the C implementations
assert test_xml_etree.ET.__name__ == module_name assert test_xml_etree.ET.__name__ == module_name
with warnings.catch_warnings(), CleanContext(): with warnings.catch_warnings(), CleanContext():
# Search behaviour is broken if search path starts with "/". # Search behaviour is broken if search path starts with "/".
ignore("This search is broken in 1.3 and earlier, and will be fixed " 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) test_support.run_doctest(test_xml_etree, verbosity=True)
# The module should not be changed by the tests # The module should not be changed by the tests
assert test_xml_etree.ET.__name__ == module_name assert test_xml_etree.ET.__name__ == module_name
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()

View File

@ -22,13 +22,18 @@ def test_main():
test_support.run_doctest(test_xml_etree_c, verbosity=True) test_support.run_doctest(test_xml_etree_c, verbosity=True)
# Assign the C implementation before running the doctests # Assign the C implementation before running the doctests
# Patch the __name__, to prevent confusion with the pure Python test
pyET = test_xml_etree.ET pyET = test_xml_etree.ET
py__name__ = test_xml_etree.__name__
test_xml_etree.ET = cET test_xml_etree.ET = cET
if __name__ != '__main__':
test_xml_etree.__name__ = __name__
try: try:
# Run the same test suite as xml.etree.ElementTree # Run the same test suite as xml.etree.ElementTree
test_xml_etree.test_main(module_name='xml.etree.cElementTree') test_xml_etree.test_main(module_name='xml.etree.cElementTree')
finally: finally:
test_xml_etree.ET = pyET test_xml_etree.ET = pyET
test_xml_etree.__name__ = py__name__
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()

View File

@ -833,7 +833,7 @@ PLATMACDIRS= plat-mac plat-mac/Carbon plat-mac/lib-scriptpackages \
plat-mac/lib-scriptpackages/Terminal plat-mac/lib-scriptpackages/Terminal
PLATMACPATH=:plat-mac:plat-mac/lib-scriptpackages PLATMACPATH=:plat-mac:plat-mac/lib-scriptpackages
LIBSUBDIRS= lib-tk site-packages test test/output test/data \ LIBSUBDIRS= lib-tk site-packages test test/output test/data \
test/decimaltestdata \ test/decimaltestdata test/xmltestdata \
encodings compiler hotshot \ encodings compiler hotshot \
email email/mime email/test email/test/data \ email email/mime email/test email/test/data \
json json/tests \ json json/tests \

View File

@ -1005,8 +1005,6 @@ def add_files(db):
lib.add_file("audiotest.au") lib.add_file("audiotest.au")
lib.add_file("cfgparser.1") lib.add_file("cfgparser.1")
lib.add_file("sgml_input.html") lib.add_file("sgml_input.html")
lib.add_file("test.xml")
lib.add_file("test.xml.out")
lib.add_file("testtar.tar") lib.add_file("testtar.tar")
lib.add_file("test_difflib_expect.html") lib.add_file("test_difflib_expect.html")
lib.add_file("check_soundcard.vbs") lib.add_file("check_soundcard.vbs")
@ -1018,6 +1016,9 @@ def add_files(db):
lib.add_file("zipdir.zip") lib.add_file("zipdir.zip")
if dir=='decimaltestdata': if dir=='decimaltestdata':
lib.glob("*.decTest") lib.glob("*.decTest")
if dir=='xmltestdata':
lib.glob("*.xml")
lib.add_file("test.xml.out")
if dir=='output': if dir=='output':
lib.glob("test_*") lib.glob("test_*")
if dir=='idlelib': if dir=='idlelib':