mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
(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. ........
This commit is contained in:
parent
1bfd0cc5d4
commit
41fe615539
14 changed files with 60 additions and 95 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue