diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-31 21:21:54 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-31 21:21:54 (GMT) |
commit | 26cc99da2a350f3093c9d7055794daef2034e2a4 (patch) | |
tree | ee127e7cde89d971b3313aa9250ca0aaf1458667 | |
parent | f7f2d6f51e8ea429b9db44eed0dcc6a4e22708df (diff) | |
download | cpython-26cc99da2a350f3093c9d7055794daef2034e2a4.zip cpython-26cc99da2a350f3093c9d7055794daef2034e2a4.tar.gz cpython-26cc99da2a350f3093c9d7055794daef2034e2a4.tar.bz2 |
Fix test for xml.etree when using a non-ascii path. And use check_warnings instead of catch_warnings.
-rw-r--r-- | Lib/test/test_xml_etree.py | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 9797b53..ad3f112 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -12,6 +12,7 @@ # except if the test is specific to the Python implementation. import sys +import cgi from test import test_support from test.test_support import findfile @@ -1292,7 +1293,7 @@ XINCLUDE["default.xml"] = """\ <p>Example.</p> <xi:include href="{}"/> </document> -""".format(SIMPLE_XMLFILE) +""".format(cgi.escape(SIMPLE_XMLFILE, True)) def xinclude_loader(href, parse="xml", encoding=None): try: @@ -1793,6 +1794,24 @@ def check_issue6565(): class CleanContext(object): """Provide default namespace mapping and path cache.""" + checkwarnings = None + + def __init__(self, quiet=False): + deprecations = ( + # Search behaviour is broken if search path starts with "/". + ("This search is broken in 1.3 and earlier, and will be fixed " + "in a future version. If you rely on the current behaviour, " + "change it to '.+'", FutureWarning), + # Element.getchildren() and Element.getiterator() are deprecated. + ("This method will be removed in future versions. " + "Use .+ instead.", DeprecationWarning), + ("This method will be removed in future versions. " + "Use .+ instead.", PendingDeprecationWarning), + # XMLParser.doctype() is deprecated. + ("This method of XMLParser is deprecated. Define doctype.. " + "method on the TreeBuilder target.", DeprecationWarning)) + self.checkwarnings = test_support.check_warnings(*deprecations, + quiet=quiet) def __enter__(self): from xml.etree import ElementTree @@ -1802,35 +1821,26 @@ class CleanContext(object): ElementTree._namespace_map = self._nsmap.copy() # Copy the path cache (should be empty) ElementTree.ElementPath._cache = self._path_cache.copy() + self.checkwarnings.__enter__() def __exit__(self, *args): from xml.etree import ElementTree # Restore mapping and path cache ElementTree._namespace_map = self._nsmap ElementTree.ElementPath._cache = self._path_cache + self.checkwarnings.__exit__(*args) def test_main(module_name='xml.etree.ElementTree'): - import warnings from test import test_xml_etree - def ignore(message, category=DeprecationWarning): - warnings.filterwarnings("ignore", message, category) + + use_py_module = (module_name == 'xml.etree.ElementTree') # 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 " - "in a future version. If you rely on the current behaviour, " - "change it to '.+'", FutureWarning) - # Element.getchildren() and Element.getiterator() are deprecated. - ignore("This method will be removed in future versions. " - "Use .+ instead.") - # XMLParser.doctype() is deprecated. - ignore("This method of XMLParser is deprecated. " - "Define doctype.. method on the TreeBuilder target.") - + # XXX the C module should give the same warnings as the Python module + with CleanContext(quiet=not use_py_module): test_support.run_doctest(test_xml_etree, verbosity=True) # The module should not be changed by the tests |