diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-04-02 18:52:12 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-04-02 18:52:12 (GMT) |
commit | 41fe6155394edf0ef65d125b27ceb8d1e37f72d3 (patch) | |
tree | 68af315f367bba93ba4d7d370e755bccd79c047f /Lib/test/test_xml_etree.py | |
parent | 1bfd0cc5d40018a6dd9f279d6d7acb829c76cc8f (diff) | |
download | cpython-41fe6155394edf0ef65d125b27ceb8d1e37f72d3.zip cpython-41fe6155394edf0ef65d125b27ceb8d1e37f72d3.tar.gz cpython-41fe6155394edf0ef65d125b27ceb8d1e37f72d3.tar.bz2 |
(partially)
Merged revisions 79534,79537,79539,79558,79606 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79534 | florent.xicluna | 2010-03-31 23:21:54 +0200 (mer, 31 mar 2010) | 2 lines
Fix test for xml.etree when using a non-ascii path. And use check_warnings instead of catch_warnings.
........
r79537 | florent.xicluna | 2010-03-31 23:40:32 +0200 (mer, 31 mar 2010) | 2 lines
Fix typo
........
r79539 | florent.xicluna | 2010-04-01 00:01:03 +0200 (jeu, 01 avr 2010) | 2 lines
Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
........
r79558 | florent.xicluna | 2010-04-01 20:17:09 +0200 (jeu, 01 avr 2010) | 2 lines
#7092: Fix some -3 warnings, and fix Lib/platform.py when the path contains a double-quote.
........
r79606 | florent.xicluna | 2010-04-02 19:26:42 +0200 (ven, 02 avr 2010) | 2 lines
Backport some robotparser test and skip the test if the external resource is not available.
........
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r-- | Lib/test/test_xml_etree.py | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index f1990d1..249ac64 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 support from test.support import findfile @@ -1305,7 +1306,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: @@ -1808,6 +1809,23 @@ 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 = support.check_warnings(*deprecations, quiet=quiet) def __enter__(self): from xml.etree import ElementTree @@ -1817,35 +1835,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): support.run_doctest(test_xml_etree, verbosity=True) # The module should not be changed by the tests |