1212# except if the test is specific to the Python implementation.
1313
1414import sys
15+ import cgi
1516
1617from test import test_support
1718from test .test_support import findfile
@@ -1292,7 +1293,7 @@ def processinginstruction():
12921293 <p>Example.</p>
12931294 <xi:include href="{}"/>
12941295</document>
1295- """ .format (SIMPLE_XMLFILE )
1296+ """ .format (cgi . escape ( SIMPLE_XMLFILE , True ) )
12961297
12971298def xinclude_loader (href , parse = "xml" , encoding = None ):
12981299 try :
@@ -1793,6 +1794,24 @@ def check_issue6565():
17931794
17941795class CleanContext (object ):
17951796 """Provide default namespace mapping and path cache."""
1797+ checkwarnings = None
1798+
1799+ def __init__ (self , quiet = False ):
1800+ deprecations = (
1801+ # Search behaviour is broken if search path starts with "/".
1802+ ("This search is broken in 1.3 and earlier, and will be fixed "
1803+ "in a future version. If you rely on the current behaviour, "
1804+ "change it to '.+'" , FutureWarning ),
1805+ # Element.getchildren() and Element.getiterator() are deprecated.
1806+ ("This method will be removed in future versions. "
1807+ "Use .+ instead." , DeprecationWarning ),
1808+ ("This method will be removed in future versions. "
1809+ "Use .+ instead." , PendingDeprecationWarning ),
1810+ # XMLParser.doctype() is deprecated.
1811+ ("This method of XMLParser is deprecated. Define doctype.. "
1812+ "method on the TreeBuilder target." , DeprecationWarning ))
1813+ self .checkwarnings = test_support .check_warnings (* deprecations ,
1814+ quiet = quiet )
17961815
17971816 def __enter__ (self ):
17981817 from xml .etree import ElementTree
@@ -1802,35 +1821,26 @@ def __enter__(self):
18021821 ElementTree ._namespace_map = self ._nsmap .copy ()
18031822 # Copy the path cache (should be empty)
18041823 ElementTree .ElementPath ._cache = self ._path_cache .copy ()
1824+ self .checkwarnings .__enter__ ()
18051825
18061826 def __exit__ (self , * args ):
18071827 from xml .etree import ElementTree
18081828 # Restore mapping and path cache
18091829 ElementTree ._namespace_map = self ._nsmap
18101830 ElementTree .ElementPath ._cache = self ._path_cache
1831+ self .checkwarnings .__exit__ (* args )
18111832
18121833
18131834def test_main (module_name = 'xml.etree.ElementTree' ):
1814- import warnings
18151835 from test import test_xml_etree
1816- def ignore ( message , category = DeprecationWarning ):
1817- warnings . filterwarnings ( "ignore" , message , category )
1836+
1837+ use_py_module = ( module_name == 'xml.etree.ElementTree' )
18181838
18191839 # The same doctests are used for both the Python and the C implementations
18201840 assert test_xml_etree .ET .__name__ == module_name
18211841
1822- with warnings .catch_warnings (), CleanContext ():
1823- # Search behaviour is broken if search path starts with "/".
1824- ignore ("This search is broken in 1.3 and earlier, and will be fixed "
1825- "in a future version. If you rely on the current behaviour, "
1826- "change it to '.+'" , FutureWarning )
1827- # Element.getchildren() and Element.getiterator() are deprecated.
1828- ignore ("This method will be removed in future versions. "
1829- "Use .+ instead." )
1830- # XMLParser.doctype() is deprecated.
1831- ignore ("This method of XMLParser is deprecated. "
1832- "Define doctype.. method on the TreeBuilder target." )
1833-
1842+ # XXX the C module should give the same warnings as the Python module
1843+ with CleanContext (quiet = not use_py_module ):
18341844 test_support .run_doctest (test_xml_etree , verbosity = True )
18351845
18361846 # The module should not be changed by the tests
0 commit comments