From 13ba1a1c6571dad26e3030525556ec4b552b0865 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Sat, 13 Mar 2010 11:18:49 +0000 Subject: [PATCH] Move the xml test data to their own directory. --- Lib/test/test_minidom.py | 2 +- Lib/test/test_sax.py | 17 ++++--- Lib/test/test_xml_etree.py | 45 ++++++++++--------- Lib/test/test_xml_etree_c.py | 5 +++ .../{samples => xmltestdata}/simple-ns.xml | 0 Lib/test/{samples => xmltestdata}/simple.xml | 0 Lib/test/{ => xmltestdata}/test.xml | 0 Lib/test/{ => xmltestdata}/test.xml.out | 0 Makefile.pre.in | 2 +- Tools/msi/msi.py | 5 ++- 10 files changed, 45 insertions(+), 31 deletions(-) rename Lib/test/{samples => xmltestdata}/simple-ns.xml (100%) rename Lib/test/{samples => xmltestdata}/simple.xml (100%) rename Lib/test/{ => xmltestdata}/test.xml (100%) rename Lib/test/{ => xmltestdata}/test.xml.out (100%) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 7ccb8f40c76..a8c0b10ac87 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 c5829852f1e..22048e6f7a0 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 bc8b620eff2..b99e42a5823 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 = """\ text @@ -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) @@ -572,7 +575,7 @@ def parsefile(): texttail - >>> tree = ET.parse("samples/simple-ns.xml") + >>> tree = ET.parse(SIMPLE_NS_XMLFILE) >>> normalize_crlf(tree) >>> tree.write(sys.stdout) @@ -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()) text @@ -593,7 +596,7 @@ def parsefile(): >>> parser = ET.XMLTreeBuilder() # 1.2 compatibility - >>> parser.feed(open("samples/simple.xml").read()) + >>> parser.feed(open(SIMPLE_XMLFILE).read()) >>> print serialize(parser.close()) text @@ -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()) text @@ -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"] = """\

Example.

- +
-""" +""".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 7e978de1b1a..78a6a9241c9 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 similarity index 100% rename from Lib/test/samples/simple-ns.xml rename to Lib/test/xmltestdata/simple-ns.xml diff --git a/Lib/test/samples/simple.xml b/Lib/test/xmltestdata/simple.xml similarity index 100% rename from Lib/test/samples/simple.xml rename to Lib/test/xmltestdata/simple.xml diff --git a/Lib/test/test.xml b/Lib/test/xmltestdata/test.xml similarity index 100% rename from Lib/test/test.xml rename to Lib/test/xmltestdata/test.xml diff --git a/Lib/test/test.xml.out b/Lib/test/xmltestdata/test.xml.out similarity index 100% rename from Lib/test/test.xml.out rename to Lib/test/xmltestdata/test.xml.out diff --git a/Makefile.pre.in b/Makefile.pre.in index 2247a566e4b..d2fb4beeb5c 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -833,7 +833,7 @@ PLATMACDIRS= plat-mac plat-mac/Carbon plat-mac/lib-scriptpackages \ plat-mac/lib-scriptpackages/Terminal PLATMACPATH=:plat-mac:plat-mac/lib-scriptpackages LIBSUBDIRS= lib-tk site-packages test test/output test/data \ - test/decimaltestdata \ + test/decimaltestdata test/xmltestdata \ encodings compiler hotshot \ email email/mime email/test email/test/data \ json json/tests \ diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py index eba29ccfa9c..84215a12631 100644 --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -1005,8 +1005,6 @@ def add_files(db): lib.add_file("audiotest.au") lib.add_file("cfgparser.1") 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("test_difflib_expect.html") lib.add_file("check_soundcard.vbs") @@ -1018,6 +1016,9 @@ def add_files(db): lib.add_file("zipdir.zip") if dir=='decimaltestdata': lib.glob("*.decTest") + if dir=='xmltestdata': + lib.glob("*.xml") + lib.add_file("test.xml.out") if dir=='output': lib.glob("test_*") if dir=='idlelib':